summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfcolin2005-05-20 15:29:54 +0000
committerfcolin2005-05-20 15:29:54 +0000
commit5a19a3603418ed80bd39fc3a260ff6557045f7b0 (patch)
tree966cc8b2fcd3b81aaaec5d7b28f75b7469f571f0
parente1b08a3c4cd478ed73b78152c9ec5252bcfc395a (diff)
downloadivy-c-5a19a3603418ed80bd39fc3a260ff6557045f7b0.zip
ivy-c-5a19a3603418ed80bd39fc3a260ff6557045f7b0.tar.gz
ivy-c-5a19a3603418ed80bd39fc3a260ff6557045f7b0.tar.bz2
ivy-c-5a19a3603418ed80bd39fc3a260ff6557045f7b0.tar.xz
portages des modifications sur windows
-rwxr-xr-xsrc/Makefile.win3297
-rw-r--r--src/ivy.c21
-rw-r--r--src/ivysocket.c59
-rw-r--r--src/ivysocket.h5
4 files changed, 130 insertions, 52 deletions
diff --git a/src/Makefile.win32 b/src/Makefile.win32
new file mode 100755
index 0000000..dab95dd
--- /dev/null
+++ b/src/Makefile.win32
@@ -0,0 +1,97 @@
+#
+# Ivy, C interface
+#
+# Copyright (C) 1997-2002
+# Centre d'Études de la Navigation Aérienne
+#
+# Makefile
+#
+# Authors: François-Régis Colin <fcolin@cena.fr>
+# Stéphane Chatty <chatty@cena.fr>
+# Yannick Jestin <jestin@cena.fr>
+#
+# Please refer to file version.h for the
+# copyright notice regarding this software
+#
+
+
+# change this in version.h too !!!!
+MAJOR=3
+MINOR=7
+
+PCREINC = -I "C:\Program Files\GnuWin32\include" #`pcre-config --cflags`
+PCRELIB = "C:\Program Files\GnuWin32\lib\libpcre.lib" #`pcre-config --libs`
+
+PCRE_OPT = PCRE_CASELESS
+REGCOMP_OPT = REG_ICASE
+
+# PCRE_OPT = 0
+# REGCOMP_OPT = REG_EXTENDED
+
+
+#PCREOBJ = `pcre-config --prefix`/lib/libpcre.a
+PCREOBJ =
+
+#CC=gcc
+#CFLAGS = -g -Wall
+CFLAGS = -DWIN32 -nologo
+#LIBTOOL=ar q # linux and solaris
+#LIBTOOL=libtool -static -o
+LIBTOOL=lib -nologo /out:
+
+#REGEXP = -DGNU_REGEXP -DREGCOMP_OPT=$(REGCOMP_OPT) # deprecated !
+REGEXP= -DUSE_PCRE_REGEX -DPCRE_OPT=$(PCRE_OPT)
+# on activeTCL , set #define CHANNEL to null, and add ivyloop.obj in the ivytcl target,
+# see below
+CHANNEL = -DTCL_CHANNEL_INTEGRATION
+
+
+OBJ = ivyloop.obj timer.obj ivysocket.obj ivy.obj
+
+# WINDOWS add ivyloop.obj if TCL_CHANNEL_INTEGRATION is not set
+TARGETS = ivyprobe ivyperf
+TARGETLIBS=libivy.dll
+
+.c.obj:
+ $(CC) $(CFLAGS) -c $*.c
+
+all: static-libs commands shared-libs
+
+static-libs: libivy.lib
+
+shared-libs: $(TARGETLIBS)
+
+commands: $(TARGETS)
+
+ivy.obj: ivy.c
+ $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivy.c
+
+
+ivyprobe: ivyprobe.obj libivy.lib
+ $(CC) $(CFLAGS) -o $@ ivyprobe.obj libivy.lib wsock32.lib $(PCRELIB)
+
+ivyprobe.obj : ivyprobe.c
+ $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) -c ivyprobe.c -o $@
+
+ivyperf: ivyperf.obj libivy.lib
+ $(CC) $(CFLAGS) -o $@ ivyperf.obj libivy.lib wsock32.lib $(PCRELIB)
+
+ivyperf.obj : ivyperf.c
+ $(CC) $(CFLAGS) $(REGEXP) $(PCREINC) -c ivyperf.c -o $@
+
+
+libivy.lib: $(OBJ)
+ del /f $@
+ $(LIBTOOL)$@ $(OBJ)
+
+
+# TODO this PCREOBJ is a dirty hack
+
+libivy.dll: $(OBJ)
+ $(CC) /dll -o $@ $(OBJ) $(PCRELIB)
+
+clean:
+ -del /f $(TARGETS) $(TARGETLIBS) *.obj *.a *.dll *~
+
+
+
diff --git a/src/ivy.c b/src/ivy.c
index 21e1841..ec1fc53 100644
--- a/src/ivy.c
+++ b/src/ivy.c
@@ -17,7 +17,10 @@
*/
#include <stdlib.h>
+#ifdef WIN32
+#else
#include <arpa/inet.h>
+#endif
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
@@ -186,6 +189,9 @@ static void IvyCleanup()
static int
MsgCall (const char *message, MsgSndPtr msg, Client client)
{
+ static char *buffer = NULL; /* Use satic mem to eliminate multiple call to malloc /free */
+ static int size = 0; /* donc non reentrant !!!! */
+ int offset = 0;
int ovector[OVECSIZE];
int index;
int rc=pcre_exec(
@@ -204,19 +210,18 @@ MsgCall (const char *message, MsgSndPtr msg, Client client)
// il faut essayer d'envoyer le message en une seule fois sur la socket
// pour eviter au maximun de passer dans le select plusieur fois par message du protocole Ivy
// pour eviter la latence ( PB de perfo detecte par ivyperf ping roudtrip )
- SocketSendBuffered( client, "%d %d" ARG_START ,Msg, msg->id);
+ offset += make_message_var( &buffer, &size, offset, "%d %d" ARG_START ,Msg, msg->id);
#ifdef DEBUG
printf( "Send matching args count %ld\n",msg->regexp.re_nsub);
#endif
index=1;
while ( index<rc ) {
- SocketSendBuffered( client, "%.*s" ARG_END , ovector[2*index+1]- ovector[2*index],
+ offset += make_message_var( &buffer, &size, offset, "%.*s" ARG_END , ovector[2*index+1]- ovector[2*index],
message + ovector[2*index]);
++index;
}
-
- SocketSendBuffered (client, "\n");
- SocketFlush( client );
+ offset += make_message_var( &buffer, &size, offset, "\n");
+ SocketSendRaw(client, buffer , offset);
return 1;
}
@@ -836,7 +841,7 @@ IvyBindMsg (MsgCallback callback, void *user_data, const char *fmt_regex, ... )
MsgRcvPtr msg;
va_start (ap, fmt_regex );
- make_message( &buffer, &size, fmt_regex, ap );
+ make_message( &buffer, &size, 0, fmt_regex, ap );
va_end (ap );
/* add Msg to the query list */
@@ -864,7 +869,7 @@ int IvySendMsg(const char *fmt, ...)
va_list ap;
va_start( ap, fmt );
- make_message( &buffer, &size, fmt, ap );
+ make_message( &buffer, &size, 0, fmt, ap );
va_end ( ap );
/* recherche dans la liste des requetes recues de mes clients */
@@ -884,7 +889,7 @@ void IvySendError( IvyClientPtr app, int id, const char *fmt, ... )
va_list ap;
va_start( ap, fmt );
- make_message( &buffer, &size, fmt, ap );
+ make_message( &buffer, &size, 0, fmt, ap );
va_end ( ap );
MsgSendTo( app->client, Error, id, buffer);
}
diff --git a/src/ivysocket.c b/src/ivysocket.c
index 1ce7305..1bb9c62 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -22,7 +22,6 @@
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
-#include <sys/ioctl.h>
#ifdef WIN32
#define close closesocket
@@ -63,7 +62,6 @@ struct _client {
struct sockaddr_in from;
SocketInterpretation interpretation;
void (*handle_delete)(Client client, void *data);
- FILE *socket_output; /* Handle buffered output */
char terminator; /* character delimiter of the message */
long buffer_size;
char *buffer; /* dynamicaly reallocated */
@@ -79,7 +77,7 @@ WSADATA WsaData;
#endif
// fonction de formtage a la printf d'un buffer avec reallocation dynamique
-int make_message(char ** buffer, int *size, const char *fmt, va_list ap)
+int make_message(char ** buffer, int *size, int offset, const char *fmt, va_list ap)
{
/* Guess we need no more than BUFFER_INIT_SIZE bytes. */
int n;
@@ -92,7 +90,11 @@ int make_message(char ** buffer, int *size, const char *fmt, va_list ap)
}
while (1) {
/* Try to print in the allocated space. */
- n = vsnprintf (*buffer, *size, fmt, ap);
+#ifdef WIN32
+ n = _vsnprintf (*buffer + offset, *size - offset, fmt, ap);
+#else
+ n = vsnprintf (*buffer + offset, *size - offset, fmt, ap);
+#endif
/* If that worked, return the string size. */
if (n > -1 && n < *size)
return n;
@@ -105,7 +107,15 @@ int make_message(char ** buffer, int *size, const char *fmt, va_list ap)
return -1;
}
}
-
+int make_message_var(char ** buffer, int *size, int offset, const char *fmt, ... )
+{
+ va_list ap;
+ int len;
+ va_start (ap, fmt );
+ len = make_message (buffer,size, offset, fmt, ap );
+ va_end (ap );
+ return len;
+}
void SocketInit()
{
@@ -235,12 +245,6 @@ static void HandleServer(Channel channel, HANDLE fd, void *data)
client->ptr = client->buffer;
client->handle_delete = server->handle_delete;
client->data = (*server->create) (client );
- client->socket_output = fdopen( client->fd, "w" );
- if (!client->socket_output )
- {
- perror("Socket Buffered output fdopen:");
- exit(0);
- }
}
Server SocketServer(unsigned short port,
@@ -399,25 +403,10 @@ void SocketSend (Client client, char *fmt, ... )
if (!client)
return;
va_start (ap, fmt );
- len = make_message (&buffer,&size, fmt, ap );
+ len = make_message (&buffer,&size, 0, fmt, ap );
SocketSendRaw (client, buffer, len );
va_end (ap );
}
-void SocketSendBuffered (Client client, char *fmt, ... )
-{
- va_list ap;
- if (!client)
- return;
- va_start (ap, fmt );
- vfprintf (client->socket_output, fmt, ap );
- va_end (ap );
-}
-void SocketFlush ( Client client )
-{
- if (!client)
- return;
- fflush( client->socket_output );
-}
void *SocketGetData (Client client )
{
@@ -433,7 +422,7 @@ void SocketBroadcast ( char *fmt, ... )
int len;
va_start (ap, fmt );
- len = make_message (&buffer, &size, fmt, ap );
+ len = make_message (&buffer, &size, 0, fmt, ap );
va_end (ap );
IVY_LIST_EACH (clients_list, client )
{
@@ -507,12 +496,6 @@ Client SocketConnectAddr (struct in_addr * addr, unsigned short port,
client->from.sin_family = AF_INET;
client->from.sin_addr = *addr;
client->from.sin_port = htons (port);
- client->socket_output = fdopen( client->fd, "w" );
- if (!client->socket_output )
- {
- perror("Socket Buffered output fdopen:");
- exit(0);
- }
return client;
}
// TODO factoriser avec HandleRead !!!!
@@ -637,12 +620,6 @@ Client SocketBroadcastCreate (unsigned short port,
client->interpretation = interpretation;
client->ptr = client->buffer;
client->data = data;
- client->socket_output = fdopen( client->fd, "w" );
- if (!client->socket_output )
- {
- perror("Socket Buffered output fdopen:");
- exit(0);
- }
return client;
}
@@ -658,7 +635,7 @@ void SocketSendBroadcast (Client client, unsigned long host, unsigned short port
return;
va_start (ap, fmt );
- len = make_message (&buffer, &size, fmt, ap );
+ len = make_message (&buffer, &size, 0, fmt, ap );
/* Send UDP packet to the dest */
remote.sin_family = AF_INET;
remote.sin_addr.s_addr = htonl (host );
diff --git a/src/ivysocket.h b/src/ivysocket.h
index 5dfdf0a..4602b64 100644
--- a/src/ivysocket.h
+++ b/src/ivysocket.h
@@ -49,7 +49,8 @@ extern "C" {
extern void SocketInit();
/* utility fonction do make vsprintf without buffer limit */
-extern int make_message(char ** buffer, int *size, const char *fmt, va_list ap);
+extern int make_message(char ** buffer, int *size, int offset, const char *fmt, va_list ap);
+extern int make_message_var(char ** buffer, int *size, int offset, const char *fmt, ...);
/* Forward def */
typedef struct _client *Client;
@@ -68,8 +69,6 @@ extern void SocketServerClose( Server server );
extern void SocketClose( Client client );
extern void SocketSend( Client client, char *fmt, ... );
-extern void SocketSendBuffered (Client client, char *fmt, ... );
-extern void SocketFlush ( Client client );
extern void SocketSendRaw( Client client, char *buffer, int len );
extern char *SocketGetPeerHost( Client client );
extern void SocketSetData( Client client, void *data );