#include "tcp.h"
#include <netdb.h>
#include <netinet/in.h>
#include <fcntl.h>
Go to the source code of this file.
Functions | |
TCP_CONNECTION | tcp_accept (TCP_SOCKET sock) |
Accept an incoming connection. | |
int | tcp_close (TCP_CONNECTION conn) |
Close a TCP connection. | |
TCP_CONNECTION | tcp_connect (const char *host, int port) |
Make a TCP connection to the specified host on the specified port. | |
TCP_SOCKET | tcp_listen (const char *host, int port) |
Listen for incoming connections. | |
int | tcp_read (TCP_CONNECTION conn, void *buf, int len) |
Read from a TCP connection. | |
int | tcp_setblocking (TCP_CONNECTION conn, int blocking) |
Make a connection blocking on nonblocking. | |
int | tcp_write (TCP_CONNECTION conn, const void *buf, int len) |
Write to a TCP connection. |
TCP_CONNECTION tcp_accept | ( | TCP_SOCKET | sock | ) |
int tcp_close | ( | TCP_CONNECTION | conn | ) |
TCP_CONNECTION tcp_connect | ( | const char * | host, | |
int | port | |||
) |
Make a TCP connection to the specified host on the specified port.
host | The host (name or IP address) of the machine to connect to. | |
port | The port number to connect to. |
Definition at line 82 of file tcp.c.
References tcp_close(), and TCP_ERROR.
TCP_SOCKET tcp_listen | ( | const char * | host, | |
int | port | |||
) |
Listen for incoming connections.
host | The address to listen on. Use NULL to listen on all local adresses. | |
port | The port to listen on. |
Definition at line 200 of file tcp.c.
References tcp_close(), and TCP_ERROR.
int tcp_read | ( | TCP_CONNECTION | conn, | |
void * | buf, | |||
int | len | |||
) |
Read from a TCP connection.
Up to len bytes are read and placed into buf. Note that the number of bytes read may be less than len.
conn | The connection to read from. | |
buf | The buffer to place the bytes into. | |
len | The maximum number of bytes to read; typically equal to the size of buf. |
Definition at line 137 of file tcp.c.
References tcp_recv.
int tcp_setblocking | ( | TCP_CONNECTION | conn, | |
int | blocking | |||
) |
Make a connection blocking on nonblocking.
Blocking affects what happens when a read is performed on a connection when there are not currently any bytes available to be read. A blocking connection will block the read until bytes are available. A non-blocking connection will signal an error and set errno to EAGAIN.
A blocking connection should be used when you want to read bytes from the connection and, if none are currently available, wait until they are.
Non-blocking connections should be used when you want to read bytes from a connection, but, if none are currently available, do something else instead.
conn | The connection to adjust. | |
blocking | 0 to make the connection blocking, any other value to make it nonblocking. |
Definition at line 177 of file tcp.c.
References TCP_ERROR.
int tcp_write | ( | TCP_CONNECTION | conn, | |
const void * | buf, | |||
int | len | |||
) |
Write to a TCP connection.
Writes up to len bytes from buf to the connection conn. Note that fewer than len bytes may be written. Always check the return value, which indicates the number of bytes actually written.
conn | The connection to write to. | |
buf | The buffer containing the bytes to be written. | |
len | The maximum number of bytes to write. |
Definition at line 153 of file tcp.c.
References tcp_send.