Gromacs  2019
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
#include "config.h"
#include <netinet/in.h>
#include <sys/socket.h>
+ Include dependency graph for imdsocket.h:

Description

Implements the parts of the vmdsock.h interface needed for IMD communication.

Author
Martin Hoefling, Carsten Kutzner ckutz.nosp@m.ne@g.nosp@m.wdg.d.nosp@m.e

For more information, see https://www-s.ks.uiuc.edu/Research/vmd/imd/ for general IMD information and https://www-s.ks.uiuc.edu/Research/vmd/imd/code/imdapi.tar.gz for the IMD reference implementation and API.

Functions

IMDSocket * imdsock_create ()
 Create an IMD master socket. More...
 
int imdsock_bind (IMDSocket *sock, int port)
 Bind the IMD socket to address and port. More...
 
int imd_sock_listen (IMDSocket *sock)
 Set socket to listening state. More...
 
IMDSocket * imdsock_accept (IMDSocket *sock)
 Accept incoming connection and redirect to client socket. More...
 
int imdsock_getport (IMDSocket *sock, int *port)
 Get the port number used for IMD connection. More...
 
int imdsock_write (IMDSocket *sock, const char *buffer, int length)
 Write to socket. More...
 
int imdsock_read (IMDSocket *sock, char *buffer, int length)
 Read from socket. More...
 
void imdsock_shutdown (IMDSocket *sock)
 Shutdown the socket. More...
 
int imdsock_destroy (IMDSocket *sock)
 Close the socket and free the sock struct memory. More...
 
int imdsock_tryread (IMDSocket *sock, int timeoutsec, int timeoutusec)
 Try to read from the socket. More...
 

Function Documentation

int imd_sock_listen ( IMDSocket *  sock)

Set socket to listening state.

Prints out an error message if unsuccessful.

Parameters
sockThe IMD socket.
Returns
0 if successful.
IMDSocket* imdsock_accept ( IMDSocket *  sock)

Accept incoming connection and redirect to client socket.

Prints out an error message if unsuccessful.

Parameters
sockThe IMD socket.
Returns
IMD socket if successful, NULL otherwise.
int imdsock_bind ( IMDSocket *  sock,
int  port 
)

Bind the IMD socket to address and port.

Prints out an error message if unsuccessful. If port == 0, bind() assigns a free port automatically.

Parameters
sockThe IMD socket.
portThe port to bind to.
Returns
0 if successful.
IMDSocket* imdsock_create ( )

Create an IMD master socket.

Returns
The IMD socket if successful. Otherwise prints an error message and returns NULL.
int imdsock_destroy ( IMDSocket *  sock)

Close the socket and free the sock struct memory.

Writes an error message if unsuccessful.

Parameters
sockThe IMD socket.
Returns
1 on success, or 0 if unsuccessful.
int imdsock_getport ( IMDSocket *  sock,
int *  port 
)

Get the port number used for IMD connection.

Prints out an error message if unsuccessful.

Parameters
sockThe IMD socket.
portThe assigned port number.
Returns
0 if successful, an error code otherwise.
int imdsock_read ( IMDSocket *  sock,
char *  buffer,
int  length 
)

Read from socket.

Parameters
sockThe IMD socket.
bufferBuffer to put the read data.
lengthNumber of bytes to read.
Returns
The number of bytes read, or -1 for errors.
void imdsock_shutdown ( IMDSocket *  sock)

Shutdown the socket.

Parameters
sockThe IMD socket.
int imdsock_tryread ( IMDSocket *  sock,
int  timeoutsec,
int  timeoutusec 
)

Try to read from the socket.

Time out after waiting the interval specified. Print an error message if unsuccessful.

Parameters
sockThe IMD socket.
timeoutsecTime out seconds
timeoutusecTime out microseconds
int imdsock_write ( IMDSocket *  sock,
const char *  buffer,
int  length 
)

Write to socket.

Parameters
sockThe IMD socket.
bufferThe data to write.
lengthNumber of bytes to write.
Returns
The number of bytes written, or -1.