summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfcolin2008-04-11 16:21:04 +0000
committerfcolin2008-04-11 16:21:04 +0000
commitdb656ec297cd2bdfdbfdf1ee4dab0085f3198492 (patch)
treea2b157c7838e2f73590021f7b63462ddf98e196d /src
parent3152da9d5a99a95ce75fee6c378a3b0711e28bb3 (diff)
downloadivy-c-db656ec297cd2bdfdbfdf1ee4dab0085f3198492.zip
ivy-c-db656ec297cd2bdfdbfdf1ee4dab0085f3198492.tar.gz
ivy-c-db656ec297cd2bdfdbfdf1ee4dab0085f3198492.tar.bz2
ivy-c-db656ec297cd2bdfdbfdf1ee4dab0085f3198492.tar.xz
Modification pour compilation sous Windows
Diffstat (limited to 'src')
-rw-r--r--src/ivy.c4
-rw-r--r--src/ivybuffer.c8
-rw-r--r--src/ivyfifo.c10
-rw-r--r--src/ivysocket.c34
4 files changed, 48 insertions, 8 deletions
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 <stdlib.h>
#ifdef WIN32
#include <windows.h>
+#define snprintf _snprintf
#else
#include <sys/time.h>
#include <arpa/inet.h>
@@ -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 <stdarg.h>
#include <string.h>
+#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 <stdlib.h>
#include <string.h>
#include <sys/types.h>
+#ifdef WIN32
+#include <windows.h>
+#else
#include <sys/socket.h>
+#endif
#include <stdio.h> // 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 <fcntl.h>
#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;