int _System soclose(int);
# endif
#endif
+#ifdef __EMX__
+#include <sys/select.h>
+#endif
+
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
# endif
#endif
+#else
+ /* undefine for OSX - its really an int */
+# ifdef __DARWIN__
+# undef SOCKLEN_T
+# define SOCKLEN_T int
+# endif
#endif /* SOCKLEN_T */
/*
m_local = NULL;
m_peer = NULL;
m_error = GSOCK_NOERROR;
- m_server = FALSE;
- m_stream = TRUE;
+ m_server = false;
+ m_stream = true;
m_gui_dependent = NULL;
- m_non_blocking = FALSE;
+ m_non_blocking = false;
+ m_reusable = false;
m_timeout = 10*60*1000;
/* 10 minutes * 60 sec * 1000 millisec */
- m_establishing = FALSE;
+ m_establishing = false;
assert(gs_gui_functions);
/* Per-socket GUI-specific initialization */
}
/* Initialize all fields */
- m_stream = TRUE;
- m_server = TRUE;
+ m_stream = true;
+ m_server = true;
/* Create the socket */
m_fd = socket(m_local->m_realfamily, SOCK_STREAM, 0);
m_error = GSOCK_IOERR;
return GSOCK_IOERR;
}
-#if defined(__EMX__) || defined(__VISAGECPP__)
- ioctl(m_fd, FIONBIO, (char*)&arg, sizeof(arg));
-#else
ioctl(m_fd, FIONBIO, &arg);
-#endif
gs_gui_functions->Enable_Events(this);
/* allow a socket to re-bind if the socket is in the TIME_WAIT
}
/* Initialize all fields */
- connection->m_server = FALSE;
- connection->m_stream = TRUE;
+ connection->m_server = false;
+ connection->m_stream = true;
/* Setup the peer address field */
connection->m_peer = GAddress_new();
return connection;
}
-int GSocket::SetReusable()
+bool GSocket::SetReusable()
{
/* socket must not be null, and must not be in use/already bound */
if (this && m_fd == INVALID_SOCKET) {
- m_reusable = TRUE;
- return TRUE;
+ m_reusable = true;
+ return true;
}
- return FALSE;
+ return false;
}
/* Client specific parts */
/* Streamed or dgram socket? */
m_stream = (stream == GSOCK_STREAMED);
- m_server = FALSE;
- m_establishing = FALSE;
+ m_server = false;
+ m_establishing = false;
/* Create the socket */
m_fd = socket(m_peer->m_realfamily,
int error;
SOCKLEN_T len = sizeof(error);
- getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (void*) &error, &len);
+ getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*) &error, &len);
if (!error)
return GSOCK_NOERROR;
*/
if ((err == EINPROGRESS) && (m_non_blocking))
{
- m_establishing = TRUE;
+ m_establishing = true;
m_error = GSOCK_WOULDBLOCK;
return GSOCK_WOULDBLOCK;
}
}
/* Initialize all fields */
- m_stream = FALSE;
- m_server = FALSE;
+ m_stream = false;
+ m_server = false;
/* Create the socket */
m_fd = socket(m_local->m_realfamily, SOCK_DGRAM, 0);
/* Do not use a static struct, Linux can garble it */
tv.tv_sec = m_timeout / 1000;
- tv.tv_usec = (m_timeout % 1000) / 1000;
+ tv.tv_usec = (m_timeout % 1000) * 1000;
FD_ZERO(&readfds);
FD_ZERO(&writefds);
*/
if ((m_detected & GSOCK_LOST_FLAG) != 0)
{
- m_establishing = FALSE;
+ m_establishing = false;
return (GSOCK_LOST_FLAG & flags);
}
else
{
m_detected = GSOCK_LOST_FLAG;
- m_establishing = FALSE;
+ m_establishing = false;
/* LOST event: Abort any further processing */
return (GSOCK_LOST_FLAG & flags);
int error;
SOCKLEN_T len = sizeof(error);
- m_establishing = FALSE;
+ m_establishing = false;
- getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (void*)&error, &len);
+ getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len);
if (error)
{
/* Check for exceptions and errors (is this useful in Unices?) */
if (FD_ISSET(m_fd, &exceptfds))
{
- m_establishing = FALSE;
+ m_establishing = false;
m_detected = GSOCK_LOST_FLAG;
/* LOST event: Abort any further processing */
* Sets the socket to non-blocking mode. All IO calls will return
* immediately.
*/
-void GSocket::SetNonBlocking(int non_block)
+void GSocket::SetNonBlocking(bool non_block)
{
assert(this);
GSocketError GSocket::GetSockOpt(int level, int optname,
void *optval, int *optlen)
{
- if (getsockopt(m_fd, level, optname, optval, (SOCKLEN_T*)optlen) == 0)
+ if (getsockopt(m_fd, level, optname, (char*)optval, (SOCKLEN_T*)optlen) == 0)
{
return GSOCK_NOERROR;
}
GSocketError GSocket::SetSockOpt(int level, int optname,
const void *optval, int optlen)
{
- if (setsockopt(m_fd, level, optname, optval, optlen) == 0)
+ if (setsockopt(m_fd, level, optname, (const char*)optval, optlen) == 0)
{
return GSOCK_NOERROR;
}
*/
if ((m_detected & GSOCK_LOST_FLAG) != 0)
{
- m_establishing = FALSE;
+ m_establishing = false;
CALL_CALLBACK(this, GSOCK_LOST);
Shutdown();
*/
if ((m_detected & GSOCK_LOST_FLAG) != 0)
{
- m_establishing = FALSE;
+ m_establishing = false;
CALL_CALLBACK(this, GSOCK_LOST);
Shutdown();
int error;
SOCKLEN_T len = sizeof(error);
- m_establishing = FALSE;
+ m_establishing = false;
- getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (void*)&error, &len);
+ getsockopt(m_fd, SOL_SOCKET, SO_ERROR, (char*)&error, &len);
if (error)
{
return GSOCK_INVPORT;
}
+#if defined(__WXPM__) && defined(__EMX__)
+ se = getservbyname(port, (char*)protocol);
+#else
se = getservbyname(port, protocol);
+#endif
if (!se)
{
/* the cast to int suppresses compiler warnings about subscript having the