Server Wait On Clients System - API Documentation  v1.6.4
Server Wait On Clients System.
tcp.c File Reference

TCP connection processing functions. More...

#include <errno.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <syslog.h>
#include <unistd.h>
#include <libmgec/libmgec.h>
#include <libmgec/mge-errno.h>
#include <swoc/libswoccommon.h>
Include dependency graph for tcp.c:

Functions

int prep_recv_sock (int *sockfd, int *portno)
 Prepare TCP socket to receive connections. More...
 
int init_conn (int *sockfd, int *portno, char *srv)
 Initiate TCP stream socket connection. More...
 
int est_connect (int *sfd, char *serv, int *portno, struct addrinfo *hints, enum comms_mode *mode)
 Establish send or receive connection. More...
 
int listen_sock (const int *sfd)
 Set TCP socket to listen. More...
 
int close_sock (const int *sockfd)
 Close TCP socket. More...
 

Detailed Description

TCP connection processing functions.

Author
Copyright (C) 2017-2022 Mark Grant

Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0-only

Version
v1.1.10 ==== 17/09/2022

Function Documentation

◆ close_sock()

int close_sock ( const int *  sockfd)

Close TCP socket.

Equivalent to close() with error handling. On error mge_errno is set.

Parameters
sockfdThe socket file descriptor.
Returns
0 on success, < zero on failure.

◆ est_connect()

int est_connect ( int *  sfd,
char *  serv,
int *  portno,
struct addrinfo *  hints,
enum comms_mode mode 
)

Establish send or receive connection.

Bind or connect depending on mode - listen or send. On error mge_errno is set.

Parameters
sfdThe socket file descriptor.
servThe server name.
portnoThe port number.
hintsThe hints for getaddrinfo().
modesend_mode or recv_mode.
Returns
0 on success, < zero on failure.

◆ init_conn()

int init_conn ( int *  sockfd,
int *  portno,
char *  srv 
)

Initiate TCP stream socket connection.

On error mge_errno is set.

Parameters
sockfdThe socket file descriptor.
portnoThe port number.
srvThe server name.
Returns
0 on success, < zero on failure.

◆ listen_sock()

int listen_sock ( const int *  sfd)

Set TCP socket to listen.

Equivalent to listen() with error handling. A race is possible with other swoc invocations to listen on that socket, so if it is in use do a few retries. On error mge_errno is set.

Parameters
sfdThe socket file descriptor.
Returns
0 on success, < zero on failure.

◆ prep_recv_sock()

int prep_recv_sock ( int *  sockfd,
int *  portno 
)

Prepare TCP socket to receive connections.

On error mge_errno is set.

Parameters
sockfdThe socket file descriptor.
portnoThe port number.
Returns
0 on success, < zero on failure.