Server Wait On Clients System - API Documentation v1.8.3
Server Wait On Clients System.
Loading...
Searching...
No Matches
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.
int init_conn (int *sockfd, int *portno, const char *srv)
 Initiate TCP stream socket connection.
int est_connect (int *sfd, const char *serv, int *portno, struct addrinfo *hints, enum comms_mode *mode)
 Establish send or receive connection.
int listen_sock (const int *sfd)
 Set TCP socket to listen.
int close_sock (const int *sockfd)
 Close TCP socket.

Detailed Description

TCP connection processing functions.

Author
Copyright (C) 2017-2023 Mark Grant

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

Version
v1.2.0 ==== 26/11/2023

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,
const 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,
const 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.