NAMD
Classes | Macros | Functions
imd.C File Reference
#include "imd.h"
#include "vmdsock.h"
#include <string.h>
#include <errno.h>
#include <stdlib.h>

Go to the source code of this file.

Classes

struct  IMDheader
 
union  netint
 structure used to perform byte swapping operations More...
 

Macros

#define HEADERSIZE   8
 

Functions

static void swap4 (char *data, int ndata)
 
static int32 imd_htonl (int32 h)
 
static int32 imd_ntohl (int32 n)
 
static void fill_header (IMDheader *header, IMDType type, int32 length)
 
static void swap_header (IMDheader *header)
 
static int32 imd_readn (void *s, char *ptr, int32 n)
 
static int32 imd_writen (void *s, const char *ptr, int32 n)
 
int imd_disconnect (void *s)
 
int imd_pause (void *s)
 
int imd_kill (void *s)
 
int imd_go (void *s)
 
int imd_handshake (void *s, const int IMDVersion)
 
int imd_trate (void *s, int32 rate)
 
std::vector< char > toTypeVector (const IMDSessionInfo *info)
 
int imd_sessioninfo (void *s, const IMDSessionInfo *info)
 
int imd_send_mdcomm (void *s, int32 n, const int32 *indices, const float *forces)
 
int imd_send_energies (void *s, const IMDEnergies *energies)
 
int imd_send_fcoords (void *s, int32 n, const float *coords)
 
int imd_send_velocities (void *s, int32 n, const float *vels)
 
int imd_send_forces (void *s, int32 n, const float *forces)
 
int imd_send_box (void *s, const IMDBox *box)
 
int imd_send_time (void *s, const IMDTime *time)
 
IMDType imd_recv_header_nolengthswap (void *s, int32 *length)
 
int imd_recv_handshake (void *s)
 Receive header and data. More...
 
IMDType imd_recv_header (void *s, int32 *length)
 
int imd_recv_mdcomm (void *s, int32 n, int32 *indices, float *forces)
 
int imd_recv_energies (void *s, IMDEnergies *energies)
 
int imd_recv_fcoords (void *s, int32 n, float *coords)
 
int imd_recv_velocities (void *s, int32 n, float *vels)
 
int imd_recv_forces (void *s, int32 n, float *forces)
 
int imd_recv_box (void *s, IMDBox *box)
 
int imd_recv_time (void *s, IMDTime *time)
 

Macro Definition Documentation

◆ HEADERSIZE

#define HEADERSIZE   8

Function Documentation

◆ fill_header()

static void fill_header ( IMDheader header,
IMDType  type,
int32  length 
)
static

Definition at line 59 of file imd.C.

References imd_htonl(), IMDheader::length, and IMDheader::type.

Referenced by imd_disconnect(), imd_go(), imd_handshake(), imd_kill(), imd_pause(), imd_send_box(), imd_send_energies(), imd_send_fcoords(), imd_send_forces(), imd_send_mdcomm(), imd_send_time(), imd_send_velocities(), imd_sessioninfo(), and imd_trate().

59  {
60  header->type = imd_htonl((int32)type);
61  header->length = imd_htonl(length);
62 }
int32_t int32
Definition: common.h:38
static int32 imd_htonl(int32 h)
Definition: imd.C:44
int32 length
Definition: imd.C:11
int32 type
Definition: imd.C:10

◆ imd_disconnect()

int imd_disconnect ( void *  s)

Definition at line 107 of file imd.C.

References fill_header(), HEADERSIZE, IMD_DISCONNECT, and imd_writen().

107  {
108  IMDheader header;
109  fill_header(&header, IMD_DISCONNECT, 0);
110  return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE);
111 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14

◆ imd_go()

int imd_go ( void *  s)

Definition at line 125 of file imd.C.

References fill_header(), HEADERSIZE, IMD_GO, and imd_writen().

Referenced by imd_recv_handshake().

125  {
126  IMDheader header;
127  fill_header(&header, IMD_GO, 0);
128  return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE);
129 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:19

◆ imd_handshake()

int imd_handshake ( void *  s,
const int  IMDVersion 
)

Definition at line 132 of file imd.C.

References fill_header(), HEADERSIZE, IMD_HANDSHAKE, imd_writen(), and IMDheader::length.

Referenced by my_imd_connect().

132  {
133  IMDheader header;
134  fill_header(&header, IMD_HANDSHAKE, 1);
135  header.length = IMDVersion; // Not byteswapped!
136  return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE);
137 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
int32 length
Definition: imd.C:11

◆ imd_htonl()

static int32 imd_htonl ( int32  h)
static

Definition at line 44 of file imd.C.

References netint::b, netint::high, netint::highest, netint::i, netint::low, and netint::lowest.

Referenced by fill_header().

44  {
45  netint n;
46  n.b.highest = h >> 24;
47  n.b.high = h >> 16;
48  n.b.low = h >> 8;
49  n.b.lowest = h;
50  return n.i;
51 }
structure used to perform byte swapping operations
Definition: imd.C:34
int32 i
Definition: imd.C:35
unsigned int low
Definition: imd.C:39
struct netint::@50 b
unsigned int lowest
Definition: imd.C:40
unsigned int high
Definition: imd.C:38
unsigned int highest
Definition: imd.C:37

◆ imd_kill()

int imd_kill ( void *  s)

Definition at line 119 of file imd.C.

References fill_header(), HEADERSIZE, IMD_KILL, and imd_writen().

119  {
120  IMDheader header;
121  fill_header(&header, IMD_KILL, 0);
122  return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE);
123 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:21

◆ imd_ntohl()

static int32 imd_ntohl ( int32  n)
static

Definition at line 53 of file imd.C.

References netint::b, netint::high, netint::highest, netint::i, netint::low, and netint::lowest.

Referenced by swap_header().

53  {
54  netint u;
55  u.i = n;
56  return (u.b.highest << 24 | u.b.high << 16 | u.b.low << 8 | u.b.lowest);
57 }
structure used to perform byte swapping operations
Definition: imd.C:34
int32 i
Definition: imd.C:35
unsigned int low
Definition: imd.C:39
struct netint::@50 b
unsigned int lowest
Definition: imd.C:40
unsigned int high
Definition: imd.C:38
unsigned int highest
Definition: imd.C:37

◆ imd_pause()

int imd_pause ( void *  s)

Definition at line 113 of file imd.C.

References fill_header(), HEADERSIZE, IMD_PAUSE, and imd_writen().

113  {
114  IMDheader header;
115  fill_header(&header, IMD_PAUSE, 0);
116  return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE);
117 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:23

◆ imd_readn()

static int32 imd_readn ( void *  s,
char *  ptr,
int32  n 
)
static

Definition at line 69 of file imd.C.

References vmdsock_read().

Referenced by imd_recv_box(), imd_recv_energies(), imd_recv_fcoords(), imd_recv_forces(), imd_recv_header(), imd_recv_header_nolengthswap(), imd_recv_mdcomm(), imd_recv_time(), and imd_recv_velocities().

69  {
70  int32 nleft;
71  int32 nread;
72 
73  nleft = n;
74  while (nleft > 0) {
75  if ((nread = vmdsock_read(s, ptr, nleft)) < 0) {
76  if (errno == EINTR)
77  nread = 0; /* and call read() again */
78  else
79  return -1;
80  } else if (nread == 0)
81  break; /* EOF */
82  nleft -= nread;
83  ptr += nread;
84  }
85  return n-nleft;
86 }
int32_t int32
Definition: common.h:38
int vmdsock_read(void *v, void *buf, int len)
Definition: vmdsock.C:154

◆ imd_recv_box()

int imd_recv_box ( void *  s,
IMDBox box 
)

Definition at line 310 of file imd.C.

References imd_readn().

310  {
311  return (imd_readn(s, (char *)box, sizeof(IMDBox)) != sizeof(IMDBox));
312 }
Definition: imd.h:55
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_recv_energies()

int imd_recv_energies ( void *  s,
IMDEnergies energies 
)

Definition at line 293 of file imd.C.

References imd_readn().

Referenced by GlobalMasterIMD::get_vmd_forces().

293  {
294  return (imd_readn(s, (char *)energies, sizeof(IMDEnergies))
295  != sizeof(IMDEnergies));
296 }
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_recv_fcoords()

int imd_recv_fcoords ( void *  s,
int32  n,
float *  coords 
)

Definition at line 298 of file imd.C.

References coords, and imd_readn().

Referenced by GlobalMasterIMD::get_vmd_forces().

298  {
299  return (imd_readn(s, (char *)coords, 12*n) != 12*n);
300 }
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69
static float * coords
Definition: ScriptTcl.C:67

◆ imd_recv_forces()

int imd_recv_forces ( void *  s,
int32  n,
float *  forces 
)

Definition at line 306 of file imd.C.

References imd_readn().

306  {
307  return (imd_readn(s, (char *)forces, 12*n) != 12*n);
308 }
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_recv_handshake()

int imd_recv_handshake ( void *  s)

Receive header and data.

Definition at line 253 of file imd.C.

References imd_go(), IMD_HANDSHAKE, imd_recv_header_nolengthswap(), IMDv2, swap4(), and vmdsock_selread().

253  {
254  // Wait 5 seconds for the handshake to come
255  if (vmdsock_selread(s, 5) != 1) return -1;
256 
257  // Check to see that a valid handshake was received
258  int32 buf;
259  IMDType type = imd_recv_header_nolengthswap(s, &buf);
260  if (type != IMD_HANDSHAKE) return -1;
261 
262  // Check its endianness, as well as the IMD version.
263  if (buf == static_cast<int>(IMDversion_t::IMDv2)) {
264  if (!imd_go(s)) return 0;
265  return -1;
266  }
267  swap4((char *)&buf, 4);
268  if (buf == static_cast<int>(IMDversion_t::IMDv2)) {
269  if (!imd_go(s)) return 1;
270  }
271 
272  // We failed to determine endianness.
273  return -1;
274 }
int vmdsock_selread(void *v, int sec)
Definition: vmdsock.C:177
IMDType imd_recv_header_nolengthswap(void *s, int32 *length)
Definition: imd.C:244
int32_t int32
Definition: common.h:38
IMDType
Definition: imd.h:15
static void swap4(char *data, int ndata)
Definition: imd.C:16
int imd_go(void *s)
Definition: imd.C:125
Definition: common.h:275

◆ imd_recv_header()

IMDType imd_recv_header ( void *  s,
int32 length 
)

Definition at line 276 of file imd.C.

References HEADERSIZE, IMD_IOERROR, imd_readn(), and swap_header().

Referenced by GlobalMasterIMD::get_vmd_forces(), and my_imd_connect().

276  {
277  IMDheader header;
278  if (imd_readn(s, (char *)&header, HEADERSIZE) != HEADERSIZE)
279  return IMD_IOERROR;
280  int i;
281  char *ch = (char*)(&header);
282  swap_header(&header);
283  *length = header.length;
284  return IMDType(header.type);
285 }
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
IMDType
Definition: imd.h:15
static void swap_header(IMDheader *header)
Definition: imd.C:64
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_recv_header_nolengthswap()

IMDType imd_recv_header_nolengthswap ( void *  s,
int32 length 
)

Definition at line 244 of file imd.C.

References HEADERSIZE, IMD_IOERROR, imd_readn(), and swap_header().

Referenced by imd_recv_handshake().

244  {
245  IMDheader header;
246  if (imd_readn(s, (char *)&header, HEADERSIZE) != HEADERSIZE)
247  return IMD_IOERROR;
248  *length = header.length;
249  swap_header(&header);
250  return IMDType(header.type);
251 }
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
IMDType
Definition: imd.h:15
static void swap_header(IMDheader *header)
Definition: imd.C:64
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_recv_mdcomm()

int imd_recv_mdcomm ( void *  s,
int32  n,
int32 indices,
float *  forces 
)

Definition at line 287 of file imd.C.

References imd_readn().

Referenced by GlobalMasterIMD::get_vmd_forces().

287  {
288  if (imd_readn(s, (char *)indices, 4*n) != 4*n) return 1;
289  if (imd_readn(s, (char *)forces, 12*n) != 12*n) return 1;
290  return 0;
291 }
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_recv_time()

int imd_recv_time ( void *  s,
IMDTime time 
)

Definition at line 314 of file imd.C.

References imd_readn().

314  {
315  return (imd_readn(s, (char *)time, sizeof(IMDTime)) != sizeof(IMDTime));
316 }
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69
Definition: imd.h:49

◆ imd_recv_velocities()

int imd_recv_velocities ( void *  s,
int32  n,
float *  vels 
)

Definition at line 302 of file imd.C.

References imd_readn().

302  {
303  return (imd_readn(s, (char *)vels, 12*n) != 12*n);
304 }
static int32 imd_readn(void *s, char *ptr, int32 n)
Definition: imd.C:69

◆ imd_send_box()

int imd_send_box ( void *  s,
const IMDBox box 
)

Definition at line 222 of file imd.C.

References fill_header(), HEADERSIZE, IMD_BOX, and imd_writen().

Referenced by GlobalMasterIMD::send_box().

222  {
223  int32 size = HEADERSIZE+sizeof(IMDBox);
224  char *buf = new char[size];
225  fill_header((IMDheader *)buf, IMD_BOX, 1);
226  memcpy((void *)(buf+HEADERSIZE), (const void *)box, sizeof(IMDBox));
227  int rc = (imd_writen(s, buf, size) != size);
228  delete [] buf;
229  return rc;
230 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:55
Definition: imd.h:30

◆ imd_send_energies()

int imd_send_energies ( void *  s,
const IMDEnergies energies 
)

Definition at line 182 of file imd.C.

References fill_header(), HEADERSIZE, IMD_ENERGIES, and imd_writen().

Referenced by GlobalMasterIMD::send_energies().

182  {
183  int32 size = HEADERSIZE+sizeof(IMDEnergies);
184  char *buf = new char[size];
185  fill_header((IMDheader *)buf, IMD_ENERGIES, 1);
186  memcpy((void *)(buf+HEADERSIZE), (const void *)energies, sizeof(IMDEnergies));
187  int rc = (imd_writen(s, buf, size) != size);
188  delete [] buf;
189  return rc;
190 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14

◆ imd_send_fcoords()

int imd_send_fcoords ( void *  s,
int32  n,
const float *  coords 
)

Definition at line 192 of file imd.C.

References coords, fill_header(), HEADERSIZE, IMD_FCOORDS, and imd_writen().

Referenced by GlobalMasterIMD::send_fcoords().

192  {
193  int32 size = HEADERSIZE+12*n;
194  char *buf = new char[size];
195  fill_header((IMDheader *)buf, IMD_FCOORDS, n);
196  memcpy((void *)(buf+HEADERSIZE), (const void *)coords, 12*n);
197  int rc = (imd_writen(s, buf, size) != size);
198  delete [] buf;
199  return rc;
200 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14
static float * coords
Definition: ScriptTcl.C:67

◆ imd_send_forces()

int imd_send_forces ( void *  s,
int32  n,
const float *  forces 
)

Definition at line 212 of file imd.C.

References fill_header(), HEADERSIZE, IMD_FORCES, and imd_writen().

Referenced by GlobalMasterIMD::send_forces().

212  {
213  int32 size = HEADERSIZE+3*n*sizeof(float);
214  char *buf = new char[size];
215  fill_header((IMDheader *)buf, IMD_FORCES, n);
216  memcpy((void *)(buf+HEADERSIZE), (const void *)forces, 3*n*sizeof(float));
217  int rc = (imd_writen(s, buf, size) != size);
218  delete [] buf;
219  return rc;
220 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:32

◆ imd_send_mdcomm()

int imd_send_mdcomm ( void *  s,
int32  n,
const int32 indices,
const float *  forces 
)

Definition at line 171 of file imd.C.

References fill_header(), HEADERSIZE, IMD_MDCOMM, and imd_writen().

171  {
172  int32 size = HEADERSIZE+16*n;
173  char *buf = new char[size];
174  fill_header((IMDheader *)buf, IMD_MDCOMM, n);
175  memcpy((void *)(buf+HEADERSIZE), (const void *)indices, 4*n);
176  memcpy((void *)(buf+HEADERSIZE+4*n), (const void *)forces, 12*n);
177  int rc = (imd_writen(s, buf, size) != size);
178  delete [] buf;
179  return rc;
180 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:22

◆ imd_send_time()

int imd_send_time ( void *  s,
const IMDTime time 
)

Definition at line 232 of file imd.C.

References fill_header(), HEADERSIZE, IMD_TIME, and imd_writen().

Referenced by GlobalMasterIMD::send_time().

232  {
233  int32 size = HEADERSIZE+sizeof(IMDTime);
234  char *buf = new char[size];
235  fill_header((IMDheader *)buf, IMD_TIME, 1);
236  memcpy((void *)(buf+HEADERSIZE), (const void *)time, sizeof(IMDTime));
237  int rc = (imd_writen(s, buf, size) != size);
238  delete [] buf;
239  return rc;
240 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:49
Definition: imd.h:29

◆ imd_send_velocities()

int imd_send_velocities ( void *  s,
int32  n,
const float *  vels 
)

Definition at line 202 of file imd.C.

References fill_header(), HEADERSIZE, IMD_VELOCITIES, and imd_writen().

Referenced by GlobalMasterIMD::send_velocities().

202  {
203  int32 size = HEADERSIZE+3*n*sizeof(float);
204  char *buf = new char[size];
206  memcpy((void *)(buf+HEADERSIZE), (const void *)vels, 3*n*sizeof(float));
207  int rc = (imd_writen(s, buf, size) != size);
208  delete [] buf;
209  return rc;
210 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14

◆ imd_sessioninfo()

int imd_sessioninfo ( void *  s,
const IMDSessionInfo info 
)

Definition at line 160 of file imd.C.

References fill_header(), HEADERSIZE, IMD_SESSIONINFO, imd_writen(), and toTypeVector().

Referenced by my_imd_connect().

160  {
161  std::vector<char> infoData = toTypeVector(info);
162  int32 size = HEADERSIZE+infoData.size()*sizeof(char);
163  char *buf = new char[size];
164  fill_header((IMDheader *)buf, IMD_SESSIONINFO, static_cast<int32>(infoData.size()));
165  memcpy((void *)(buf+HEADERSIZE), (const void *)(infoData.data()), infoData.size()*sizeof(char));
166  int rc = (imd_writen(s, buf, size) != size);
167  delete [] buf;
168  return rc;
169 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
int32_t int32
Definition: common.h:38
#define HEADERSIZE
Definition: imd.C:14
std::vector< char > toTypeVector(const IMDSessionInfo *info)
Definition: imd.C:148

◆ imd_trate()

int imd_trate ( void *  s,
int32  rate 
)

Definition at line 139 of file imd.C.

References fill_header(), HEADERSIZE, IMD_TRATE, and imd_writen().

139  {
140  IMDheader header;
141  fill_header(&header, IMD_TRATE, rate);
142  return (imd_writen(s, (char *)&header, HEADERSIZE) != HEADERSIZE);
143 }
static int32 imd_writen(void *s, const char *ptr, int32 n)
Definition: imd.C:88
static void fill_header(IMDheader *header, IMDType type, int32 length)
Definition: imd.C:59
Definition: imd.C:9
#define HEADERSIZE
Definition: imd.C:14
Definition: imd.h:24

◆ imd_writen()

static int32 imd_writen ( void *  s,
const char *  ptr,
int32  n 
)
static

Definition at line 88 of file imd.C.

References vmdsock_write().

Referenced by imd_disconnect(), imd_go(), imd_handshake(), imd_kill(), imd_pause(), imd_send_box(), imd_send_energies(), imd_send_fcoords(), imd_send_forces(), imd_send_mdcomm(), imd_send_time(), imd_send_velocities(), imd_sessioninfo(), and imd_trate().

88  {
89  int32 nleft;
90  int32 nwritten;
91 
92  nleft = n;
93  while (nleft > 0) {
94  if ((nwritten = vmdsock_write(s, ptr, nleft)) <= 0) {
95  if (errno == EINTR)
96  nwritten = 0;
97  else
98  return -1;
99  }
100  nleft -= nwritten;
101  ptr += nwritten;
102  }
103  return n;
104 }
int32_t int32
Definition: common.h:38
int vmdsock_write(void *v, const void *buf, int len)
Definition: vmdsock.C:145

◆ swap4()

static void swap4 ( char *  data,
int  ndata 
)
static

Definition at line 16 of file imd.C.

Referenced by imd_recv_handshake().

16  {
17  int i;
18  char *dataptr;
19  char b0, b1;
20 
21  dataptr = data;
22  for (i=0; i<ndata; i+=4) {
23  b0 = dataptr[0];
24  b1 = dataptr[1];
25  dataptr[0] = dataptr[3];
26  dataptr[1] = dataptr[2];
27  dataptr[2] = b1;
28  dataptr[3] = b0;
29  dataptr += 4;
30  }
31 }

◆ swap_header()

static void swap_header ( IMDheader header)
static

Definition at line 64 of file imd.C.

References imd_ntohl(), IMDheader::length, and IMDheader::type.

Referenced by imd_recv_header(), and imd_recv_header_nolengthswap().

64  {
65  header->type = imd_ntohl(header->type);
66  header->length= imd_ntohl(header->length);
67 }
static int32 imd_ntohl(int32 n)
Definition: imd.C:53
int32 length
Definition: imd.C:11
int32 type
Definition: imd.C:10

◆ toTypeVector()

std::vector<char> toTypeVector ( const IMDSessionInfo info)

Definition at line 148 of file imd.C.

References IMDSessionInfo::box_switch, IMDSessionInfo::energies_switch, IMDSessionInfo::fcoords_switch, IMDSessionInfo::forces_switch, IMDSessionInfo::time_switch, IMDSessionInfo::velocities_switch, and IMDSessionInfo::wrap_switch.

Referenced by imd_sessioninfo().

148  {
149  std::vector<char> data;
150  data.push_back(static_cast<char>(info->time_switch));
151  data.push_back(static_cast<char>(info->energies_switch));
152  data.push_back(static_cast<char>(info->box_switch));
153  data.push_back(static_cast<char>(info->fcoords_switch));
154  data.push_back(static_cast<char>(info->wrap_switch));
155  data.push_back(static_cast<char>(info->velocities_switch));
156  data.push_back(static_cast<char>(info->forces_switch));
157  return data;
158 }
int wrap_switch
Definition: imd.h:66
int time_switch
Definition: imd.h:62
int box_switch
Definition: imd.h:64
int fcoords_switch
Definition: imd.h:65
int velocities_switch
Definition: imd.h:67
int forces_switch
Definition: imd.h:68
int energies_switch
Definition: imd.h:63