Skip to content

Commit 23c5082

Browse files
authored
Fix for file descriptor type difference on Windows (#56)
1 parent 668a4e7 commit 23c5082

File tree

3 files changed

+67
-20
lines changed

3 files changed

+67
-20
lines changed

pkg/stream/client.go

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ import (
99
"math/rand"
1010
"net"
1111
"net/url"
12-
"runtime"
1312
"sync"
1413
"sync/atomic"
15-
"syscall"
1614
"time"
1715
)
1816

@@ -106,24 +104,7 @@ func (c *Client) connect() error {
106104
c.tuneState.requestedMaxFrameSize = 1048576
107105

108106
var dialer = &net.Dialer{
109-
Control: func(network, address string, c syscall.RawConn) error {
110-
return c.Control(func(fd uintptr) {
111-
err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, defaultSocketBuffer)
112-
runtime.KeepAlive(fd)
113-
if err != nil {
114-
logs.LogError("Set socket option error: %s", err)
115-
return
116-
}
117-
118-
err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, defaultSocketBuffer)
119-
runtime.KeepAlive(fd)
120-
if err != nil {
121-
logs.LogError("Set socket option error: %s", err)
122-
return
123-
}
124-
125-
})
126-
},
107+
Control: controlFunc,
127108
}
128109

129110
var connection net.Conn

pkg/stream/dialer_posix.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// +build !windows
2+
3+
package stream
4+
5+
import (
6+
"runtime"
7+
"syscall"
8+
9+
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/logs"
10+
)
11+
12+
var controlFunc func(network, address string, c syscall.RawConn) error
13+
14+
func init() {
15+
controlFunc = func(network, address string, c syscall.RawConn) error {
16+
return c.Control(func(fd uintptr) {
17+
err := syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, defaultSocketBuffer)
18+
runtime.KeepAlive(fd)
19+
if err != nil {
20+
logs.LogError("Set socket option error: %s", err)
21+
return
22+
}
23+
24+
err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, defaultSocketBuffer)
25+
runtime.KeepAlive(fd)
26+
if err != nil {
27+
logs.LogError("Set socket option error: %s", err)
28+
return
29+
}
30+
31+
})
32+
}
33+
}

pkg/stream/dialer_windows.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// +build windows
2+
3+
package stream
4+
5+
import (
6+
"runtime"
7+
"syscall"
8+
9+
"github.com/rabbitmq/rabbitmq-stream-go-client/pkg/logs"
10+
)
11+
12+
var controlFunc func(network, address string, c syscall.RawConn) error
13+
14+
func init() {
15+
controlFunc = func(network, address string, c syscall.RawConn) error {
16+
return c.Control(func(fd uintptr) {
17+
err := syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_RCVBUF, defaultSocketBuffer)
18+
runtime.KeepAlive(fd)
19+
if err != nil {
20+
logs.LogError("Set socket option error: %s", err)
21+
return
22+
}
23+
24+
err = syscall.SetsockoptInt(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_SNDBUF, defaultSocketBuffer)
25+
runtime.KeepAlive(fd)
26+
if err != nil {
27+
logs.LogError("Set socket option error: %s", err)
28+
return
29+
}
30+
31+
})
32+
}
33+
}

0 commit comments

Comments
 (0)