-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added DialAssociation and ListenAssociation
These are helpers to easily run SCTP over UDP. Example adapted. I added the Association postfix to keep space for a potential Dial/Listen implementation that directly gives you a Stream. Relates to #74
- Loading branch information
Showing
8 changed files
with
91 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
all: ping pong | ||
|
||
ping: ping.go conn.go | ||
ping: ping.go | ||
go build -o $@ | ||
|
||
pong: pong.go conn.go | ||
pong: pong.go | ||
go build -o $@ -tags $@ |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package sctp | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/pion/udp" | ||
) | ||
|
||
// ListenAssociation creates a SCTP association listener | ||
func ListenAssociation(network string, laddr *net.UDPAddr, config Config) (*AssociationListener, error) { | ||
lc := udp.ListenConfig{} | ||
parent, err := lc.Listen(network, laddr) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &AssociationListener{ | ||
config: config, | ||
parent: parent, | ||
}, nil | ||
} | ||
|
||
// NewAssociationListener creates a SCTP association listener | ||
// which accepts connections from an inner Listener. | ||
// The net.Conn in the config is ignored. | ||
func NewAssociationListener(inner net.Listener, config Config) (*AssociationListener, error) { | ||
return &AssociationListener{ | ||
config: config, | ||
parent: inner, | ||
}, nil | ||
} | ||
|
||
// AssociationListener represents a SCTP association listener | ||
type AssociationListener struct { | ||
config Config | ||
parent net.Listener | ||
} | ||
|
||
// Accept waits for and returns the next association to the listener. | ||
// You have to either close or read on all connection that are created. | ||
func (l *AssociationListener) Accept() (*Association, error) { | ||
c, err := l.parent.Accept() | ||
if err != nil { | ||
return nil, err | ||
} | ||
l.config.NetConn = c | ||
return Server(l.config) | ||
} | ||
|
||
// Close closes the listener. | ||
// Any blocked Accept operations will be unblocked and return errors. | ||
// Already Accepted connections are not closed. | ||
func (l *AssociationListener) Close() error { | ||
return l.parent.Close() | ||
} | ||
|
||
// Addr returns the listener's network address. | ||
func (l *AssociationListener) Addr() net.Addr { | ||
return l.parent.Addr() | ||
} |