From db656ec297cd2bdfdbfdf1ee4dab0085f3198492 Mon Sep 17 00:00:00 2001 From: fcolin Date: Fri, 11 Apr 2008 16:21:04 +0000 Subject: Modification pour compilation sous Windows --- src/ivy.c | 4 +++- src/ivybuffer.c | 8 +++++++- src/ivyfifo.c | 10 +++++++++- src/ivysocket.c | 34 +++++++++++++++++++++++++++++----- 4 files changed, 48 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/ivy.c b/src/ivy.c index fd894fd..821f128 100644 --- a/src/ivy.c +++ b/src/ivy.c @@ -27,6 +27,7 @@ #include #ifdef WIN32 #include +#define snprintf _snprintf #else #include #include @@ -1066,6 +1067,8 @@ IvyChangeMsg (MsgRcvPtr msg, const char *fmt_regex, ... ) int IvySendMsg(const char *fmt, ...) /* version dictionnaire */ { int match_count = 0; + MsgSndDictPtr msgSendDict; + static IvyBuffer buffer = { NULL, 0, 0}; /* Use static mem to eliminate multiple call to malloc /free */ va_list ap; @@ -1143,7 +1146,6 @@ int IvySendMsg(const char *fmt, ...) /* version dictionnaire */ #else // PAS OPENMP - MsgSndDictPtr msgSendDict; for (msgSendDict=messSndByRegexp; msgSendDict ; msgSendDict=msgSendDict->hh.next) { match_count += RegexpCall (msgSendDict, buffer.data); diff --git a/src/ivybuffer.c b/src/ivybuffer.c index 9504bbf..bbb1313 100644 --- a/src/ivybuffer.c +++ b/src/ivybuffer.c @@ -23,6 +23,10 @@ #include #include +#ifdef WIN32 +#define snprintf _snprintf +#endif + #include "param.h" #include "ivybuffer.h" @@ -45,10 +49,12 @@ int make_message(IvyBuffer* buffer, const char *fmt, va_list ap) } while (1) { /* Try to print in the allocated space. */ - va_copy( ap_copy, ap ); + #ifdef WIN32 + ap_copy = ap; n = _vsnprintf (buffer->data + buffer->offset, buffer->size - buffer->offset, fmt, ap_copy); #else + va_copy( ap_copy, ap ); n = vsnprintf (buffer->data + buffer->offset, buffer->size - buffer->offset, fmt, ap_copy); #endif va_end(ap_copy); diff --git a/src/ivyfifo.c b/src/ivyfifo.c index 9bee644..e427f1d 100644 --- a/src/ivyfifo.c +++ b/src/ivyfifo.c @@ -1,7 +1,11 @@ #include #include #include +#ifdef WIN32 +#include +#else #include +#endif #include // DEBUG, pour printf #include "ivyfifo.h" #include "param.h" @@ -146,7 +150,11 @@ unsigned int IvyFifoSendSocket (IvyFifoBuffer *f, const int fd) do { maxLen = MIN ((f->end - f->rptr), IvyFifoLength(f)); - realLen = send (fd, f->rptr, maxLen, MSG_DONTWAIT); +#ifdef WIN32 + realLen = send (fd, f->rptr, maxLen, 0); +#else + realLen = send (fd, f->rptr, maxLen, MSG_DONTWAIT); +#endif IvyFifoDrain(f, realLen); // printf ("DBG> maxLen=%d realLen=%d IvyFifoLength=%d\n", // maxLen, realLen, IvyFifoLength(f)); diff --git a/src/ivysocket.c b/src/ivysocket.c index 9dbdd29..06ac27f 100644 --- a/src/ivysocket.c +++ b/src/ivysocket.c @@ -29,6 +29,7 @@ #include #ifdef WIN32 +typedef int ssize_t; #define close closesocket /*#define perror (a ) printf(a" error=%d\n",WSAGetLastError());*/ #else @@ -222,8 +223,11 @@ static void HandleServer(Channel channel, HANDLE fd, void *data) HANDLE ns; socklen_t addrlen; struct sockaddr_in remote2; +#ifdef WIN32 + u_long iMode = 1; /* non blocking Mode */ +#else long socketFlag; - +#endif TRACE( "Accepting Connection...\n"); addrlen = sizeof (remote2 ); @@ -250,10 +254,16 @@ static void HandleServer(Channel channel, HANDLE fd, void *data) client->ifb = NULL; strcpy (client->app_uuid, "init by HandleServer"); - socketFlag = fcntl (client->fd, F_GETFL); +#ifdef WIN32 + if ( ioctlsocket(client->fd,FIONBIO, &iMode ) ) + fprintf(stderr,"Warning : Setting socket in nonblock mode FAILED\n"); +#else + socketFlag = fcntl (client->fd, F_GETFL); if (fcntl (client->fd, F_SETFL, socketFlag|O_NONBLOCK)) { fprintf(stderr,"Warning : Setting socket in nonblock mode FAILED\n"); } +#endif + client->channel = IvyChannelAdd (ns, client, DeleteSocket, HandleSocket, @@ -439,10 +449,16 @@ static SendState BufferizedSocketSendRaw (const Client client, const char *buffe } else { // on tente d'ecrire direct dans la socket reallySent = send (client->fd, buffer, len, 0); - if (reallySent == len) { + if (reallySent == len) + { state = SendOk; // PAS CONGESTIONNEE - } else if (reallySent == -1) { + } else if (reallySent == -1) + { +#ifdef WIN32 + if ( WSAGetLastError() == WSAEWOULDBLOCK) { +#else if (errno == EWOULDBLOCK) { +#endif // Aucun octet n'a été envoyé, mais le send ne rend pas 0 // car 0 peut être une longueur passée au send, donc dans ce cas // send renvoie -1 et met errno a EWOULDBLOCK @@ -610,7 +626,11 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port, HANDLE handle; Client client; struct sockaddr_in remote; +#ifdef WIN32 + u_long iMode = 1; /* non blocking Mode */ +#else long socketFlag; +#endif remote.sin_family = AF_INET; remote.sin_addr = *addr; @@ -625,11 +645,15 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port, perror ("*** client connect ***"); return NULL; }; +#ifdef WIN32 + if ( ioctlsocket(handle,FIONBIO, &iMode ) ) + fprintf(stderr,"Warning : Setting socket in nonblock mode FAILED\n"); +#else socketFlag = fcntl (handle, F_GETFL); if (fcntl (handle, F_SETFL, socketFlag|O_NONBLOCK)) { fprintf(stderr,"Warning : Setting socket in nonblock mode FAILED\n"); } - +#endif IVY_LIST_ADD_START(clients_list, client ); client->buffer_size = IVY_BUFFER_SIZE; -- cgit v1.1