#define BSD_SELECT /* use Berkley Sockets select */
#include <assert.h>
-#include <sys\types.h>
+#include <sys/types.h>
+
#ifdef __EMX__
#include <sys/time.h>
#include <netinet/in.h>
#include <unistd.h>
#include <sys/un.h>
#define HAVE_INET_ADDR
+
#else
-#include <utils.h>
-#include <sys\time.h>
+
+#include <string.h>
+
+#include <sys/time.h>
#include <types.h>
-#include <in.h>
+#include <netinet/in.h>
#include <netdb.h>
#include <nerrno.h>
+
#endif
+
#if defined(__VISAGECPP__) && __IBMCPP__ < 400
-#include <machine\endian.h>
+
+#include <machine/endian.h>
#include <socket.h>
#include <ioctl.h>
#include <select.h>
#include <unistd.h>
+
+#define EBADF SOCEBADF
+
#else
-#include <sys\socket.h>
-#include <sys\ioctl.h>
-#include <sys\select.h>
+
+#include <sys/socket.h>
+#include <sys/ioctl.h>
+#include <sys/select.h>
+
#ifdef __EMX__
#define soclose(a) close(a)
#else
#endif
#endif
-#include <string.h>
#include <stdio.h>
#if (defined(__VISAGECPP__) && __IBMCPP__ < 400) || defined(__EMX__)
# ifdef min
#endif
#include <stddef.h>
#include <ctype.h>
+#include <stdlib.h>
#include <signal.h>
* Sets up this socket as a server. The local address must have been
* set with GSocket_SetLocal() before GSocket_SetServer() is called.
* Returns GSOCK_NOERROR on success, one of the following otherwise:
- *
+ *
* Error codes:
* GSOCK_INVSOCK - the socket is in use.
* GSOCK_INVADDR - the local address has not been set.
- * GSOCK_IOERR - low-level error.
+ * GSOCK_IOERR - low-level error.
*/
GSocketError GSocket_SetServer(GSocket *sck)
{
return GSOCK_IOERR;
}
- ioctl(sck->m_fd, FIONBIO, &arg);
+ ioctl(sck->m_fd, FIONBIO, (char*)&arg, sizeof(arg));
_GSocket_Enable_Events(sck);
/* Bind to the local address,
* GSOCK_TIMEDOUT - timeout, no incoming connections.
* GSOCK_WOULDBLOCK - the call would block and the socket is nonblocking.
* GSOCK_MEMERR - couldn't allocate memory.
- * GSOCK_IOERR - low-level error.
+ * GSOCK_IOERR - low-level error.
*/
GSocket *GSocket_WaitConnection(GSocket *socket)
{
return NULL;
}
- ioctl(connection->m_fd, FIONBIO, &arg);
+ ioctl(connection->m_fd, FIONBIO, (char*)&arg, sizeof(arg));
_GSocket_Enable_Events(connection);
return connection;
* GSOCK_TIMEDOUT - timeout, the connection failed.
* GSOCK_WOULDBLOCK - connection in progress (nonblocking sockets only)
* GSOCK_MEMERR - couldn't allocate memory.
- * GSOCK_IOERR - low-level error.
+ * GSOCK_IOERR - low-level error.
*/
GSocketError GSocket_Connect(GSocket *sck, GSocketStream stream)
{
return GSOCK_IOERR;
}
- ioctl(sck->m_fd, FIONBIO, &arg);
+ ioctl(sck->m_fd, FIONBIO, (char*)&arg, sizeof(arg));
_GSocket_Enable_Events(sck);
/* Connect it to the peer address, with a timeout (see below) */
ret = connect(sck->m_fd, sck->m_peer->m_addr, sck->m_peer->m_len);
printf("connect on %d to %X (%d) returned %d, errno = %d\n",
- sck->m_fd, sck->m_peer->m_addr, sck->m_peer->m_len, ret, errno);
+ sck->m_fd, sck->m_peer->m_addr, sck->m_peer->m_len, ret, errno);
if (ret == -1)
{
err = errno;
return GSOCK_IOERR;
}
- ioctl(sck->m_fd, FIONBIO, &arg);
+ ioctl(sck->m_fd, FIONBIO, (char*)&arg, sizeof(arg));
_GSocket_Enable_Events(sck);
/* Bind to the local address,
ret = _GSocket_Recv_Stream(socket, buffer, size);
else
ret = _GSocket_Recv_Dgram(socket, buffer, size);
-
+
if (ret == -1)
{
if (errno == EWOULDBLOCK)
else
socket->m_error = GSOCK_IOERR;
}
-
+
return ret;
}
int GSocket_Write(GSocket *socket, const char *buffer, int size)
-{
+{
int ret;
assert(socket != NULL);
-
+
GSocket_Debug(( "GSocket_Write #1, size %d\n", size ));
if (socket->m_fd == INVALID_SOCKET || socket->m_server)
ret = _GSocket_Send_Stream(socket, buffer, size);
else
ret = _GSocket_Send_Dgram(socket, buffer, size);
-
+
GSocket_Debug(( "GSocket_Write #4, size %d\n", size ));
if (ret == -1)
_GSocket_Enable(socket, GSOCK_OUTPUT);
return -1;
}
-
+
GSocket_Debug(( "GSocket_Write #5, size %d ret %d\n", size, ret ));
return ret;
return result;
-#else
+#else
assert(socket != NULL);
return flags & socket->m_detected;
* operation, there is still data available, the callback function will
* be called again.
* GSOCK_OUTPUT:
- * The socket is available for writing. That is, the next write call
+ * The socket is available for writing. That is, the next write call
* won't block. This event is generated only once, when the connection is
* first established, and then only if a call failed with GSOCK_WOULDBLOCK,
* when the output buffer empties again. This means that the app should
if ((flags & (1 << count)) != 0)
{
printf("Setting callback no %d for socket at %X to address %X,data %X\n",
- count, socket, callback, cdata);
+ count, socket, callback, cdata);
socket->m_cbacks[count] = callback;
socket->m_data[count] = cdata;
}
if ((flags & (1 << count)) != 0)
{
printf("Removing callback no %d for socket at %X",
- count, socket);
+ count, socket);
socket->m_cbacks[count] = NULL;
socket->m_data[count] = NULL;
}
{
int ret;
+#ifdef __EMX__
MASK_SIGNAL();
ret = send(socket->m_fd, buffer, size, 0);
UNMASK_SIGNAL();
-
+#else
+ ret = send(socket->m_fd, (char *)buffer, size, 0);
+#endif
return ret;
}
return -1;
}
+#ifdef __EMX__
MASK_SIGNAL();
ret = sendto(socket->m_fd, buffer, size, 0, addr, len);
UNMASK_SIGNAL();
+#else
+ ret = sendto(socket->m_fd, (char *)buffer, size, 0, addr, len);
+#endif
/* Frees memory allocated from _GAddress_translate_to */
free(addr);
if (inet_aton(hostname, addr) == 0)
{
#elif defined(HAVE_INET_ADDR)
- if ( (addr->s_addr = inet_addr(hostname)) == -1 )
+ addr->s_addr = inet_addr(hostname);
+ if ( addr->s_addr == -1 )
{
#else
/* Use gethostbyname by default */
- if (1)
+ int val = 1; //VA doesn't like constants in conditional expressions at all
+ if (val)
{
#endif
struct in_addr *array_addr;
address->m_error = GSOCK_INVPORT;
return GSOCK_INVPORT;
}
-
+
se = getservbyname(port, protocol);
if (!se)
{
assert(address != NULL);
CHECK_ADDRESS(address, INET);
-
+
addr = (struct sockaddr_in *)address->m_addr;
addr->sin_port = htons(port);
char *addr_buf;
struct sockaddr_in *addr;
- assert(address != NULL);
+ assert(address != NULL);
CHECK_ADDRESS(address, INET);
addr = (struct sockaddr_in *)address->m_addr;
{
struct sockaddr_in *addr;
- assert(address != NULL);
- CHECK_ADDRESS_RETVAL(address, INET, 0);
+ assert(address != NULL);
+ CHECK_ADDRESS_RETVAL(address, INET, 0);
addr = (struct sockaddr_in *)address->m_addr;
{
struct sockaddr_in *addr;
- assert(address != NULL);
- CHECK_ADDRESS_RETVAL(address, INET, 0);
+ assert(address != NULL);
+ CHECK_ADDRESS_RETVAL(address, INET, 0);
addr = (struct sockaddr_in *)address->m_addr;
return ntohs(addr->sin_port);
{
struct sockaddr_un *addr;
- assert(address != NULL);
+ assert(address != NULL);
- CHECK_ADDRESS(address, UNIX);
+ CHECK_ADDRESS(address, UNIX);
addr = ((struct sockaddr_un *)address->m_addr);
memcpy(addr->sun_path, path, strlen(path));