add socket_fastopen, socket_fastopen_connect4, socket_fastopen_connect6 and socket_quickack
parent
8bdf66a1f5
commit
88167b5ce1
@ -0,0 +1,30 @@
|
|||||||
|
.TH socket_fastopen 3
|
||||||
|
.SH NAME
|
||||||
|
socket_fastopen \- enable TCP Fast Open on a server-side TCP socket
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <socket.h>
|
||||||
|
|
||||||
|
int \fBsocket_fastopen\fP(int \fIs\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
socket_fastopen enables TCP Fast Open support on a server-side TCP
|
||||||
|
socket. Call this before socket_listen(). If the platform does not
|
||||||
|
support this functionality, returns -1 and sets errno to ENOPROTOOPT (or
|
||||||
|
ENOSYS if the platform does not define ENOPROTOOPT).
|
||||||
|
|
||||||
|
Normally socket_fastopen returns 0. If anything goes wrong, socket_fastopen
|
||||||
|
returns -1, setting errno appropriately.
|
||||||
|
|
||||||
|
.SH EXAMPLE
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
int \fIs\fR;
|
||||||
|
char \fIip\fR[4];
|
||||||
|
uint16 \fIp\fR;
|
||||||
|
|
||||||
|
\fIs\fR = socket_tcp4b();
|
||||||
|
socket_fastopen(s);
|
||||||
|
socket_bind4_reuse(s,ip,p);
|
||||||
|
socket_listen(16);
|
||||||
|
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
socket_fastopen_connect4(3), socket_fastopen_connect6(3)
|
@ -0,0 +1,58 @@
|
|||||||
|
.TH socket_fastopen_connect4 3
|
||||||
|
.SH NAME
|
||||||
|
socket_fastopen_connect4 \- make a TCP connection and send some data
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <socket.h>
|
||||||
|
|
||||||
|
ssize_t \fBsocket_fastopen_connect4\fP(int \fIs\fR,const char \fIip\fR[4],uint16 \fIport\fR,
|
||||||
|
const char* \fIbuf\fR,size_t \fIlen\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
socket_fastopen_connect4 attempts to make a connection from TCP socket \fIs\fR to
|
||||||
|
TCP port \fIport\fR on IP address \fIip\fR. If that succeeds, it
|
||||||
|
attempts to send \fIlen\fR bytes from \fIbuf\fR.
|
||||||
|
|
||||||
|
The difference to calling socket_connect4 followed by write is that, on
|
||||||
|
platforms supporting TCP Fast Open, socket_fastopen_connect4 will send
|
||||||
|
the first data packet in the third packet of the TCP handshake, saving
|
||||||
|
one useless ACK packet in network traffic.
|
||||||
|
|
||||||
|
This is only useful for protocols where the client sends the first
|
||||||
|
bytes.
|
||||||
|
|
||||||
|
socket_connect4 may return
|
||||||
|
.sp 1
|
||||||
|
.IP \(bu
|
||||||
|
>=0, to indicate that the connection succeeded and this many bytes were
|
||||||
|
sent.
|
||||||
|
.IP \(bu
|
||||||
|
-1, setting errno to error_inprogress or error_wouldblock, to indicate
|
||||||
|
that the socket is non-blocking
|
||||||
|
.IP \(bu
|
||||||
|
-1, setting errno to something else, to indicate that the connection
|
||||||
|
failed (and failed immediately, if the socket is non-blocking).
|
||||||
|
.PP
|
||||||
|
|
||||||
|
When a background connection succeeds or fails, \fIs\fR becomes
|
||||||
|
writable; you can use socket_connected to see whether the connection
|
||||||
|
succeeded. If the connection failed, socket_connected returns 0,
|
||||||
|
setting errno appropriately.
|
||||||
|
|
||||||
|
Once a TCP socket is connected, you can use the read and write
|
||||||
|
system calls to transmit data.
|
||||||
|
|
||||||
|
You can call socket_connect4 without calling socket_bind4. This has the
|
||||||
|
effect as first calling socket_bind4 with IP address 0.0.0.0 and port 0.
|
||||||
|
|
||||||
|
.SH EXAMPLE
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
int \fIs\fR;
|
||||||
|
char \fIip\fR[4];
|
||||||
|
uint16 \fIp\fR;
|
||||||
|
|
||||||
|
\fIs\fR = socket_tcp4();
|
||||||
|
socket_bind4(s,ip,p);
|
||||||
|
socket_fastopen_connect4(s,ip,p,"hello",5);
|
||||||
|
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
socket_connect4(3), socket_fastopen_connect6(3), socket_fastopen(3)
|
@ -0,0 +1,60 @@
|
|||||||
|
.TH socket_fastopen_connect6 3
|
||||||
|
.SH NAME
|
||||||
|
socket_fastopen_connect6 \- make a TCP connection and send some data
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <socket.h>
|
||||||
|
|
||||||
|
ssize_t \fBsocket_fastopen_connect6\fP(int \fIs\fR,
|
||||||
|
const char \fIip\fR[16],uint16 \fIport\fR,uint32 \fIscope_id\fR,
|
||||||
|
const char* \fIbuf\fR,size_t \fIlen\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
socket_fastopen_connect6 attempts to make a connection from TCP socket \fIs\fR to
|
||||||
|
TCP port \fIport\fR on IP address \fIip\fR. If that succeeds, it
|
||||||
|
attempts to send \fIlen\fR bytes from \fIbuf\fR.
|
||||||
|
|
||||||
|
The difference to calling socket_connect6 followed by write is that, on
|
||||||
|
platforms supporting TCP Fast Open, socket_fastopen_connect6 will send
|
||||||
|
the first data packet in the third packet of the TCP handshake, saving
|
||||||
|
one useless ACK packet in network traffic.
|
||||||
|
|
||||||
|
This is only useful for protocols where the client sends the first
|
||||||
|
bytes.
|
||||||
|
|
||||||
|
socket_connect6 may return
|
||||||
|
.sp 1
|
||||||
|
.IP \(bu
|
||||||
|
>=0, to indicate that the connection succeeded and this many bytes were
|
||||||
|
sent.
|
||||||
|
.IP \(bu
|
||||||
|
-1, setting errno to error_inprogress or error_wouldblock, to indicate
|
||||||
|
that the socket is non-blocking
|
||||||
|
.IP \(bu
|
||||||
|
-1, setting errno to something else, to indicate that the connection
|
||||||
|
failed (and failed immediately, if the socket is non-blocking).
|
||||||
|
.PP
|
||||||
|
|
||||||
|
When a background connection succeeds or fails, \fIs\fR becomes
|
||||||
|
writable; you can use socket_connected to see whether the connection
|
||||||
|
succeeded. If the connection failed, socket_connected returns 0,
|
||||||
|
setting errno appropriately.
|
||||||
|
|
||||||
|
Once a TCP socket is connected, you can use the read and write
|
||||||
|
system calls to transmit data.
|
||||||
|
|
||||||
|
You can call socket_connect6 without calling socket_bind6. This has the
|
||||||
|
effect as first calling socket_bind6 with IP address :: and port 0.
|
||||||
|
|
||||||
|
.SH EXAMPLE
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
int \fIs\fR;
|
||||||
|
char \fIip\fR[16];
|
||||||
|
uint16 \fIp\fR;
|
||||||
|
uint32 \fIscope_id\fR;
|
||||||
|
|
||||||
|
\fIs\fR = socket_tcp6b();
|
||||||
|
socket_bind6(s,ip,p);
|
||||||
|
socket_fastopen_connect6(s,ip,p,scope_id,"hello",5);
|
||||||
|
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
socket_connect6(3), socket_fastopen_connect4(3), socket_fastopen(3)
|
@ -0,0 +1,38 @@
|
|||||||
|
.TH socket_quickack 3
|
||||||
|
.SH NAME
|
||||||
|
socket_quickack \- turn TCP Quick ACK mode on or off
|
||||||
|
.SH SYNTAX
|
||||||
|
.B #include <socket.h>
|
||||||
|
|
||||||
|
int \fBsocket_quickack\fP(int \fIs\fR,int \fIvalue\fR);
|
||||||
|
.SH DESCRIPTION
|
||||||
|
socket_quickack switches TCP Quick ACK mode on (value=1) or off
|
||||||
|
(value=0). If the platform does not support this functionality, returns
|
||||||
|
-1 and sets errno to ENOPROTOOPT (or ENOSYS if the platform does not
|
||||||
|
define ENOPROTOOPT).
|
||||||
|
|
||||||
|
TCP Quick ACK mode is on by default because the operating system has to
|
||||||
|
assume it's an interactive connection. In that case, an ACK will be
|
||||||
|
sent quickly after data came in. If your code handles non-interactive
|
||||||
|
server connections, it may make sense to switch Quick ACK mode off,
|
||||||
|
telling the kernel to delay sending ACKs because the server is going to
|
||||||
|
respond to incoming requests anyway, so the ACK can be piggy-backed onto
|
||||||
|
that response, saving useless network traffic.
|
||||||
|
|
||||||
|
Normally socket_quickack returns 0. If anything goes wrong, socket_quickack
|
||||||
|
returns -1, setting errno appropriately.
|
||||||
|
|
||||||
|
.SH EXAMPLE
|
||||||
|
#include <socket.h>
|
||||||
|
|
||||||
|
int \fIs\fR;
|
||||||
|
char \fIip\fR[4];
|
||||||
|
uint16 \fIp\fR;
|
||||||
|
|
||||||
|
\fIs\fR = socket_tcp4b();
|
||||||
|
socket_quickack(s);
|
||||||
|
socket_bind4_reuse(s,ip,p);
|
||||||
|
socket_listen(16);
|
||||||
|
|
||||||
|
.SH "SEE ALSO"
|
||||||
|
socket_fastopen(3)
|
@ -0,0 +1,18 @@
|
|||||||
|
#include "socket.h"
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netinet/tcp.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
int socket_quickack(int s,int value) {
|
||||||
|
#ifdef TCP_QUICKACK
|
||||||
|
return setsockopt(s, SOL_TCP, TCP_QUICKACK, &value, sizeof(int));
|
||||||
|
#else
|
||||||
|
#ifdef ENOPROTOOPT
|
||||||
|
errno=ENOPROTOOPT;
|
||||||
|
#else
|
||||||
|
errno=ENOSYS;
|
||||||
|
#endif
|
||||||
|
return -1;
|
||||||
|
#endif
|
||||||
|
}
|
Loading…
Reference in New Issue