#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.
|
| #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.
|
| |
|
| void | open_connect_socket (int *psockfd, int *inet, int *port, char *host) |
| | Opens and connects a socket.
|
| |
| void | open_bind_socket (int *psockfd, int *inet, int *port, char *host) |
| | Opens and binds a socket.
|
| |
| void | writebuffer (int *psockfd, char *data, int *plen) |
| | Writes to a socket.
|
| |
| void | readbuffer (int *psockfd, char *data, int *plen) |
| | Reads from a socket.
|
| |
| void | listen_socket (int *psockfd, int *backlog) |
| | Listens to a socket.
|
| |
| void | accept_socket (int *psockfd, int *pclientfd) |
| | Listens to a socket.
|
| |
| void | close_socket (int *psockfd) |
| | Closes a socket.
|
| |
| void | remove_socket_file (char *host) |
| | Removes a socket file.
|
| |
| void | uwait (double *dsec) |
| | Mini-wrapper to nanosleep.
|
| |
◆ _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.
◆ open_connect_socket()
| void open_connect_socket |
( |
int * |
psockfd, |
|
|
int * |
inet, |
|
|
int * |
port, |
|
|
char * |
host |
|
) |
| |
Opens and connects a socket.
- Parameters
-
| psockfd | The id of the socket that will be created. |
| inet | An integer that determines whether the socket will be an inet or unix domain socket. Gives unix if 0, inet otherwise. |
| port | The 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. |
| host | The name of the host server (inet socket), or the full path of the UNIX socket file (unix socket). The caller is responsible for building this path, e.g. by prepending a prefix such as "/tmp/ipi_". |
- Note
- Fortran passes an extra argument for the string length, but this is ignored here for C compatibility.
Definition at line 71 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
-
| psockfd | The id of the socket that will be created. |
| inet | An integer that determines whether the socket will be an inet or unix domain socket. Gives unix if 0, inet otherwise. |
| port | The 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. |
| host | The 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 139 of file sockets.c.
◆ writebuffer()
| void writebuffer |
( |
int * |
psockfd, |
|
|
char * |
data, |
|
|
int * |
plen |
|
) |
| |
Writes to a socket.
- Parameters
-
| psockfd | The id of the socket that will be written to. |
| data | The data to be written to the socket. |
| plen | The length of the data in bytes. |
Definition at line 203 of file sockets.c.
◆ readbuffer()
| void readbuffer |
( |
int * |
psockfd, |
|
|
char * |
data, |
|
|
int * |
plen |
|
) |
| |
Reads from a socket.
- Parameters
-
| psockfd | The id of the socket that will be read from. |
| data | The storage array for data read from the socket. |
| plen | The length of the data in bytes. |
Definition at line 221 of file sockets.c.
◆ listen_socket()
| void listen_socket |
( |
int * |
psockfd, |
|
|
int * |
backlog |
|
) |
| |
Listens to a socket.
- Parameters
-
| psockfd | The id of the socket to listen. |
| n | An integer that determines the number of requests that will be queued before further requests are refused. |
Definition at line 245 of file sockets.c.
◆ accept_socket()
| void accept_socket |
( |
int * |
psockfd, |
|
|
int * |
pclientfd |
|
) |
| |
Listens to a socket.
- Parameters
-
| psockfd | The id of the socket to listen. |
| pclientfd | The id of the accepted socket. |
Definition at line 258 of file sockets.c.
◆ close_socket()
| void close_socket |
( |
int * |
psockfd | ) |
|
Closes a socket.
- Parameters
-
| psockfd | The id of the socket to close. |
Definition at line 269 of file sockets.c.
◆ remove_socket_file()
| void remove_socket_file |
( |
char * |
host | ) |
|
Removes a socket file.
- Parameters
-
| hostname | The name of the socket file to remove. |
Definition at line 275 of file sockets.c.
◆ uwait()
| void uwait |
( |
double * |
dsec | ) |
|
Mini-wrapper to nanosleep.
- Parameters
-
| dsec | number of seconds to wait (float values accepted) |
Definition at line 281 of file sockets.c.