Skip to content

Commit 54a7689

Browse files
committed
unix: add Connectx for darwin
connectx(2) can be used to initiate a connection with TCP Fast Open.
1 parent c64c51d commit 54a7689

13 files changed

+134
-0
lines changed

unix/darwin_amd64_test.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/darwin_arm64_test.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/mkerrors.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,7 @@ ccflags="$@"
552552
$2 !~ /^RTC_VL_(ACCURACY|BACKUP|DATA)/ &&
553553
$2 ~ /^(NETLINK|NLM|NLMSG|NLA|IFA|IFAN|RT|RTC|RTCF|RTN|RTPROT|RTNH|ARPHRD|ETH_P|NETNSA)_/ ||
554554
$2 ~ /^SOCK_|SK_DIAG_|SKNLGRP_$/ ||
555+
$2 ~ /^(CONNECT|SAE)_/ ||
555556
$2 ~ /^FIORDCHK$/ ||
556557
$2 ~ /^SIOC/ ||
557558
$2 ~ /^TIOC/ ||

unix/syscall_darwin.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,41 @@ func PthreadFchdir(fd int) (err error) {
566566
return pthread_fchdir_np(fd)
567567
}
568568

569+
// Connectx calls connectx(2) with the given arguments.
570+
//
571+
// - srcIf is the optional source interface.
572+
// - srcAddr is the optional source address.
573+
// - dstAddr is the destination address.
574+
//
575+
// On success, Connectx returns the number of bytes enqueued for transmission.
576+
func Connectx(fd int, srcIf uint32, srcAddr, dstAddr Sockaddr, associd SaeAssocID, flags uint32, iov []Iovec, connid *SaeConnID) (n uintptr, err error) {
577+
endpoints := SaEndpoints{
578+
Srcif: srcIf,
579+
}
580+
581+
if srcAddr != nil {
582+
addrp, addrlen, err := srcAddr.sockaddr()
583+
if err != nil {
584+
return 0, err
585+
}
586+
endpoints.Srcaddr = (*RawSockaddr)(addrp)
587+
endpoints.Srcaddrlen = uint32(addrlen)
588+
}
589+
590+
if dstAddr != nil {
591+
addrp, addrlen, err := dstAddr.sockaddr()
592+
if err != nil {
593+
return 0, err
594+
}
595+
endpoints.Dstaddr = (*RawSockaddr)(addrp)
596+
endpoints.Dstaddrlen = uint32(addrlen)
597+
}
598+
599+
err = connectx(fd, &endpoints, associd, flags, iov, &n, connid)
600+
return
601+
}
602+
603+
//sys connectx(fd int, endpoints *SaEndpoints, associd SaeAssocID, flags uint32, iov []Iovec, n *uintptr, connid *SaeConnID) (err error)
569604
//sys sendfile(infd int, outfd int, offset int64, len *int64, hdtr unsafe.Pointer, flags int) (err error)
570605

571606
//sys shmat(id int, addr uintptr, flag int) (ret uintptr, err error)

unix/types_darwin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ type XVSockPgen C.struct_xvsockpgen
177177

178178
type _Socklen C.socklen_t
179179

180+
type SaeAssocID C.sae_associd_t
181+
182+
type SaeConnID C.sae_connid_t
183+
184+
type SaEndpoints C.struct_sa_endpoints
185+
180186
type Xucred C.struct_xucred
181187

182188
type Linger C.struct_linger

unix/zerrors_darwin_amd64.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zerrors_darwin_arm64.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_darwin_amd64.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_darwin_amd64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0
248248
GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8
249249
DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB)
250250

251+
TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0
252+
JMP libc_connectx(SB)
253+
GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8
254+
DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB)
255+
251256
TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0
252257
JMP libc_sendfile(SB)
253258
GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8

unix/zsyscall_darwin_arm64.go

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/zsyscall_darwin_arm64.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ TEXT libc_pthread_fchdir_np_trampoline<>(SB),NOSPLIT,$0-0
248248
GLOBL ·libc_pthread_fchdir_np_trampoline_addr(SB), RODATA, $8
249249
DATA ·libc_pthread_fchdir_np_trampoline_addr(SB)/8, $libc_pthread_fchdir_np_trampoline<>(SB)
250250

251+
TEXT libc_connectx_trampoline<>(SB),NOSPLIT,$0-0
252+
JMP libc_connectx(SB)
253+
GLOBL ·libc_connectx_trampoline_addr(SB), RODATA, $8
254+
DATA ·libc_connectx_trampoline_addr(SB)/8, $libc_connectx_trampoline<>(SB)
255+
251256
TEXT libc_sendfile_trampoline<>(SB),NOSPLIT,$0-0
252257
JMP libc_sendfile(SB)
253258
GLOBL ·libc_sendfile_trampoline_addr(SB), RODATA, $8

unix/ztypes_darwin_amd64.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix/ztypes_darwin_arm64.go

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)