Skip to content

Commit e7931c6

Browse files
committed
wifinina: fix concurrency issues with multiple sockets
wifinina driver was not handling concurrent socket connections correctly. When trying to make multiple socket connections, the sockfd returned by the first Socket() call would be the same sockfd returned by subsequent Socket() calls. The problem is the sockfd returned by Socket() isn't used until Connect() (or Appect()). This would result in Connect() trying to use the same sockfd for multiple connections, causing wifinina fw to lock up. The solution in this PR is to create a new sockfd space managed by the driver that gives the app a unique, safe sockfd for each connection. The real underlying sock fd returned by fw is set on Connect() (or Accept()), and mapped back to the apps sockfd using a map: sockets map[int]*Socket // keyed by sockfd Where Socket has a reference to the fw sock: type Socket struct { protocol int clientConnected bool laddr netip.AddrPort // Set in Bind() raddr netip.AddrPort // Set in Connect() sock // Device socket, as returned from w.getSocket() }
1 parent 3c5e174 commit e7931c6

File tree

2 files changed

+132
-92
lines changed

2 files changed

+132
-92
lines changed

netdev/netdev.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ var (
3939
ErrNoMoreSockets = errors.New("No more sockets")
4040
ErrClosingSocket = errors.New("Error closing socket")
4141
ErrNotSupported = errors.New("Not supported")
42+
ErrInvalidSocketFd = errors.New("Invalid socket fd")
4243
)
4344

4445
// Duplicate of non-exported net.errTimeout

0 commit comments

Comments
 (0)