---
name: "socket_fastopen_connect4"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/socket_fastopen_connect4"
---

# socket\_fastopen\_connect4(3)

make a TCP connection and send some data

## NAME

socket\_fastopen\_connect4 - make a TCP connection and send some data

## SYNTAX

**#include \<libowfat/socket.h\>**

ssize\_t **socket\_fastopen\_connect4**(int *s*,const char *ip*\[4\],uint16 *port*,\
                                  const char\* *buf*,size\_t *len*);

## DESCRIPTION

socket\_fastopen\_connect4 attempts to make a connection from TCP socket *s* to TCP port *port* on IP address *ip*.  If that succeeds, it attempts to send *len* bytes from *buf*.

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

- •

  \>=0, to indicate that the connection succeeded and this many bytes were sent.

- •

  \-1, setting errno to error\_inprogress or error\_wouldblock, to indicate that the socket is non-blocking

- •

  \-1, setting errno to something else, to indicate that the connection failed (and failed immediately, if the socket is non-blocking).

When a background connection succeeds or fails, *s* 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.

## EXAMPLE

  \#include \<libowfat/socket.h\>

  int *s*;\
   char *ip*\[4\];\
   uint16 *p*;

  *s* = socket\_tcp4();\
   socket\_bind4(s,ip,p);\
   socket\_fastopen\_connect4(s,ip,p,"hello",5);

## SEE ALSO

[socket\_connect4(3)](/socket_connect4/3.md), [socket\_fastopen\_connect6(3)](/socket_fastopen_connect6/3.md), [socket\_fastopen(3)](/socket_fastopen/3.md)
