#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. More...
|
|
|
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...
|
|
◆ _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. |
- 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
-
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 137 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 201 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 219 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 243 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 256 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 267 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 273 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 279 of file sockets.c.