#include "gmxpre.h"
#include "imdsocket.h"
#include "config.h"
#include <errno.h>
#include <string.h>
#include "gromacs/imd/imd.h"
#include "gromacs/utility/fatalerror.h"
#include "gromacs/utility/smalloc.h"
#include <unistd.h>
Implements functions of imdsocket.h.
This file re-implements vmdsock.c functions from original IMD API from scratch, see imdsocket.h for references to the IMD API.
- Author
- Martin Hoefling, Carsten Kutzner ckutz.nosp@m.ne@g.nosp@m.wdg.d.nosp@m.e
|
#define | ERR_ARGS __FILE__, __LINE__, strerror(errno) |
| Simple error handling.
|
|
#define | MAXIMDCONNECTIONS 1 |
| Currently only 1 client connection is supported.
|
|
|
static void | print_IMD_error (char *file, int line, char *msg) |
| Print a nice error message on UNIX systems, using errno.h.
|
|
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...
|
|
Set socket to listening state.
Prints out an error message if unsuccessful.
- Parameters
-
- Returns
- 0 if successful.
Accept incoming connection and redirect to client socket.
Prints out an error message if unsuccessful.
- Parameters
-
- 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
-
sock | The IMD socket. |
port | The port to bind to. |
- Returns
- 0 if successful.
Create an IMD master socket.
- Returns
- The IMD socket if successful. Otherwise prints an error message and returns NULL.
Close the socket and free the sock struct memory.
Writes an error message if unsuccessful.
- Parameters
-
- 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
-
sock | The IMD socket. |
port | The assigned port number. |
- Returns
- 0 if successful, an error code otherwise.
int imdsock_read |
( |
IMDSocket * |
sock, |
|
|
char * |
buffer, |
|
|
int |
length |
|
) |
| |
Read from socket.
- Parameters
-
sock | The IMD socket. |
buffer | Buffer to put the read data. |
length | Number of bytes to read. |
- Returns
- The number of bytes read, or -1 for errors.
Shutdown the socket.
- Parameters
-
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
-
sock | The IMD socket. |
timeoutsec | Time out seconds |
timeoutusec | Time out microseconds |
int imdsock_write |
( |
IMDSocket * |
sock, |
|
|
const char * |
buffer, |
|
|
int |
length |
|
) |
| |
Write to socket.
- Parameters
-
sock | The IMD socket. |
buffer | The data to write. |
length | Number of bytes to write. |
- Returns
- The number of bytes written, or -1.