Removed unused variables.
Implemented our own byte swapping routines to prevent
deprecated-register warnings for imd.cpp and imdsocket.cpp.
Change-Id: Iaa61299f2d4dad61e8a0a0122fb402184d4d1f62
#
# This file is part of the GROMACS molecular simulation package.
#
-# Copyright (c) 2014, by the GROMACS development team, led by
+# Copyright (c) 2014,2015, by the GROMACS development team, led by
# Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
# and including many others, as listed in the AUTHORS file in the
# top-level source directory and at http://www.gromacs.org.
# To help us fund GROMACS development, we humbly ask that you cite
# the research papers on the package. Check out http://www.gromacs.org.
-file(GLOB IMD_SOURCES *.cpp *.c)
+file(GLOB IMD_SOURCES *.cpp)
set(LIBGROMACS_SOURCES ${LIBGROMACS_SOURCES} ${IMD_SOURCES} PARENT_SCOPE)
#ifdef GMX_IMD
+/*! \brief Byte swap in case we are little-endian */
+static gmx_int32_t gmx_htonl(gmx_int32_t src)
+{
+ int num = 1;
+
+ if (*(char *)&num == 1)
+ {
+ return src;
+ }
+ else
+ {
+ gmx_int32_t dest = 0;
+
+ dest |= (src & 0xFF000000) >> 24;
+ dest |= (src & 0x00FF0000) >> 8;
+ dest |= (src & 0x0000FF00) << 8;
+ dest |= (src & 0x000000FF) << 24;
+
+ return dest;
+ }
+}
+
+/*! \brief Byte-unswap 32 bit word in case we are little-endian */
+static gmx_int32_t gmx_ntohl(gmx_int32_t src)
+{
+ return gmx_htonl(src);
+}
+
/*! \brief Fills the header with message and the length argument. */
static void fill_header(IMDHeader *header, IMDMessageType type, gmx_int32_t length)
{
/* We (ab-)use htonl network function for the correct endianness */
- header->type = htonl((gmx_int32_t) type);
- header->length = htonl(length);
+ header->type = gmx_htonl((gmx_int32_t) type);
+ header->length = gmx_htonl(length);
}
static void swap_header(IMDHeader *header)
{
/* and vice versa... */
- header->type = ntohl(header->type);
- header->length = ntohl(header->length);
+ header->type = gmx_ntohl(header->type);
+ header->length = gmx_ntohl(header->length);
}
static void imd_blockconnect(t_gmx_IMD_setup *IMDsetup)
{
/* do not wait for connection, when e.g. ctrl+c is pressed and we will terminate anyways. */
- if (gmx_get_stop_condition() != gmx_stop_cond_none)
+ if (!((int) gmx_get_stop_condition() == gmx_stop_cond_none))
{
return;
}
{
int new_nforces = 0;
t_gmx_IMD_setup *IMDsetup;
- int start, end, i;
IMDsetup = ir->imd->setup;
/*
* This file is part of the GROMACS molecular simulation package.
*
- * Copyright (c) 2014, by the GROMACS development team, led by
+ * Copyright (c) 2014,2015, by the GROMACS development team, led by
* Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
* and including many others, as listed in the AUTHORS file in the
* top-level source directory and at http://www.gromacs.org.
/*! \brief Print a nice error message on UNIX systems, using errno.h. */
-static void print_IMD_error(char *file, int line, char *msg)
+static void print_IMD_error(const char *file, int line, char *msg)
{
fprintf(stderr, "%s Error in file %s on line %d.\n", IMDstr, file, line);
}
}
+/*! \brief Byte swap in case we are little-endian */
+static uint16_t gmx_htons(uint16_t src)
+{
+ uint16_t num = 1;
+
+ if (*(char *)&num == 1)
+ {
+ return src;
+ }
+ else
+ {
+ uint16_t dest = 0;
+
+ dest |= (src & 0x0000FF00) >> 8;
+ dest |= (src & 0x000000FF) << 8;
+
+ return dest;
+ }
+}
+
+/*! \brief Byte-unswap 16 bit word in case we are little-endian */
+static uint16_t gmx_ntohs(uint16_t src)
+{
+ return gmx_htons(src);
+}
+
extern IMDSocket* imdsock_create()
{
#ifdef GMX_IMD
memset(&(sock->address), 0, sizeof(sock->address));
sock->address.sin_family = PF_INET;
- sock->address.sin_port = htons(port);
+ sock->address.sin_port = gmx_htons(port);
/* Try to bind to address and port ...*/
ret = bind(sock->sockfd, (struct sockaddr *) &sock->address, sizeof(sock->address));
{
int ret;
#ifdef GMX_IMD
- struct sockaddr_in sin;
socklen_t len;
- len = sizeof(sin);
+ len = sizeof(struct sockaddr_in);
ret = getsockname(sock->sockfd, (struct sockaddr *) &(sock->address), &len);
if (ret)
{
}
else
{
- *port = ntohs(sock->address.sin_port);
+ *port = gmx_ntohs(sock->address.sin_port);
}
#else
gmx_incons("imdsock_getport called without IMD support.");
+ ret = -1;
#endif
return ret;