(git:0de0cc2)
sockets.c File Reference
#include <math.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/select.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
#include <time.h>
#include <unistd.h>

Go to the source code of this file.

Macros

#define _POSIX_C_SOURCE   200809L
 A minimal wrapper for socket communication. Contains both the functions that transmit data to the socket and read the data back out again once finished, and the function which opens the socket initially. Can be linked to a FORTRAN code that does not support sockets natively. More...
 

Functions

void open_connect_socket (int *psockfd, int *inet, int *port, char *host)
 Opens and connects a socket. More...
 
void open_bind_socket (int *psockfd, int *inet, int *port, char *host)
 Opens and binds a socket. More...
 
void writebuffer (int *psockfd, char *data, int *plen)
 Writes to a socket. More...
 
void readbuffer (int *psockfd, char *data, int *plen)
 Reads from a socket. More...
 
void listen_socket (int *psockfd, int *backlog)
 Listens to a socket. More...
 
void accept_socket (int *psockfd, int *pclientfd)
 Listens to a socket. More...
 
void close_socket (int *psockfd)
 Closes a socket. More...
 
void remove_socket_file (char *host)
 Removes a socket file. More...
 
void uwait (double *dsec)
 Mini-wrapper to nanosleep. More...
 

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

A minimal wrapper for socket communication. Contains both the functions that transmit data to the socket and read the data back out again once finished, and the function which opens the socket initially. Can be linked to a FORTRAN code that does not support sockets natively.

Author
Joshua More and Michele Ceriotti

Definition at line 41 of file sockets.c.

Function Documentation

◆ open_connect_socket()

void open_connect_socket ( int *  psockfd,
int *  inet,
int *  port,
char *  host 
)

Opens and connects a socket.

Parameters
psockfdThe id of the socket that will be created.
inetAn integer that determines whether the socket will be an inet or unix domain socket. Gives unix if 0, inet otherwise.
portThe port number for the socket to be created. Low numbers are often reserved for important channels, so use of numbers of 4 or more digits is recommended.
hostThe name of the host server.
Note
Fortran passes an extra argument for the string length, but this is ignored here for C compatibility.

Definition at line 68 of file sockets.c.

◆ open_bind_socket()

void open_bind_socket ( int *  psockfd,
int *  inet,
int *  port,
char *  host 
)

Opens and binds a socket.

Parameters
psockfdThe id of the socket that will be created.
inetAn integer that determines whether the socket will be an inet or unix domain socket. Gives unix if 0, inet otherwise.
portThe port number for the socket to be created. Low numbers are often reserved for important channels, so use of numbers of 4 or more digits is recommended.
hostThe name of the host server.
Note
Fortran passes an extra argument for the string length, but this is ignored here for C compatibility.

Definition at line 137 of file sockets.c.

Here is the caller graph for this function:

◆ writebuffer()

void writebuffer ( int *  psockfd,
char *  data,
int *  plen 
)

Writes to a socket.

Parameters
psockfdThe id of the socket that will be written to.
dataThe data to be written to the socket.
plenThe length of the data in bytes.

Definition at line 201 of file sockets.c.

Here is the caller graph for this function:

◆ readbuffer()

void readbuffer ( int *  psockfd,
char *  data,
int *  plen 
)

Reads from a socket.

Parameters
psockfdThe id of the socket that will be read from.
dataThe storage array for data read from the socket.
plenThe length of the data in bytes.

Definition at line 219 of file sockets.c.

Here is the caller graph for this function:

◆ listen_socket()

void listen_socket ( int *  psockfd,
int *  backlog 
)

Listens to a socket.

Parameters
psockfdThe id of the socket to listen.
nAn integer that determines the number of requests that will be queued before further requests are refused.

Definition at line 243 of file sockets.c.

Here is the caller graph for this function:

◆ accept_socket()

void accept_socket ( int *  psockfd,
int *  pclientfd 
)

Listens to a socket.

Parameters
psockfdThe id of the socket to listen.
pclientfdThe id of the accepted socket.

Definition at line 256 of file sockets.c.

Here is the caller graph for this function:

◆ close_socket()

void close_socket ( int *  psockfd)

Closes a socket.

Parameters
psockfdThe id of the socket to close.

Definition at line 267 of file sockets.c.

Here is the caller graph for this function:

◆ remove_socket_file()

void remove_socket_file ( char *  host)

Removes a socket file.

Parameters
hostnameThe name of the socket file to remove.

Definition at line 273 of file sockets.c.

Here is the caller graph for this function:

◆ uwait()

void uwait ( double *  dsec)

Mini-wrapper to nanosleep.

Parameters
dsecnumber of seconds to wait (float values accepted)

Definition at line 279 of file sockets.c.

Here is the caller graph for this function: