summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile9
-rw-r--r--src/ivy.c3
-rw-r--r--src/ivybind.c2
-rw-r--r--src/ivysocket.c115
-rw-r--r--src/ivysocket.h6
5 files changed, 70 insertions, 65 deletions
diff --git a/src/Makefile b/src/Makefile
index 871af95..3fe4580 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -68,9 +68,9 @@ REGEXP= -DUSE_PCRE_REGEX -DPCRE_OPT=$(PCRE_OPT)
CHANNEL = -DTCL_CHANNEL_INTEGRATION
CFLAGS = -g -Wall #-DDEBUG
-OBJ = ivyloop.o timer.o ivysocket.o ivybind.o ivy.o
-GOBJ = ivyloop.o timer.o ivysocket.o ivybind.o givy.o
-XTOBJ = ivyxtloop.o ivysocket.o ivybind.o ivy.o
+OBJ = ivyloop.o timer.o ivysocket.o ivybind.o ivyargument.o ivy.o
+GOBJ = ivyloop.o timer.o ivysocket.o ivybind.o ivyargument.o givy.o
+XTOBJ = ivyxtloop.o ivysocket.o ivybind.o ivyargument.o ivy.o
GLIBOBJ = ivyglibloop.o ivysocket.o ivybind.o ivy.o
GLUTOBJ = ivyglutloop.o ivysocket.o ivybind.o ivy.o
TCLOBJ = ivytcl.o timer.o ivysocket.o ivybind.o givy.o
@@ -101,6 +101,9 @@ ivy.o: ivy.c
ivybind.o: ivybind.c
$(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivybind.c
+ivyargument.o: ivyargument.c
+ $(CC) -c $(CFLAGS) $(REGEXP) $(PCREINC) ivyargument.c
+
givy.o: ivy.c
$(CC) -c $(CFLAGS) $(REGEXP) -o givy.o ivy.c
diff --git a/src/ivy.c b/src/ivy.c
index 11376f8..b4ea31b 100644
--- a/src/ivy.c
+++ b/src/ivy.c
@@ -259,7 +259,8 @@ static void MsgSendTo( Client client, MsgType msgtype, int id, const char *messa
{
strncpy( ptr, message , len_arg);
}
- SocketSendRaw( client, packet, len );
+ SocketSendBuf( client, packet, len ); //TODO dont do multiple buffer copy
+ SocketFlush( client );
free( packet );
}
diff --git a/src/ivybind.c b/src/ivybind.c
index 1a9d49a..cd758c6 100644
--- a/src/ivybind.c
+++ b/src/ivybind.c
@@ -41,7 +41,7 @@
#endif
struct _binding {
- struct _timer *next;
+ struct _binding *next;
#ifndef USE_PCRE_REGEX
regex_t regexp; /* la regexp sous forme machine */
regmatch_t match[MAX_MSG_FIELDS+1]; /* resultat du match */
diff --git a/src/ivysocket.c b/src/ivysocket.c
index 16991d9..6a0cbf3 100644
--- a/src/ivysocket.c
+++ b/src/ivysocket.c
@@ -62,12 +62,13 @@ struct _client {
SocketInterpretation interpretation;
SocketDelete handle_delete;
/* input buffer */
- int buffer_size;
- char *buffer; /* dynamicaly reallocated */
- char *ptr;
+ int in_buffer_size;
+ char *in_buffer; /* dynamicaly reallocated */
+ char *in_ptr;
/* output buffer */
int out_buffer_size;
char *out_buffer; /* dynamicaly reallocated */
+ char *out_ptr;
void *data;
};
@@ -150,20 +151,20 @@ static void HandleSocket (Channel channel, HANDLE fd, void *data)
socklen_t len;
/* limitation taille buffer */
- nb_to_read = client->buffer_size - (client->ptr - client->buffer );
+ nb_to_read = client->in_buffer_size - (client->in_ptr - client->in_buffer );
if (nb_to_read == 0 ) {
- client->buffer_size *= 2; /* twice old size */
- client->buffer = realloc( client->buffer, client->buffer_size );
- if (!client->buffer )
+ client->in_buffer_size *= 2; /* twice old size */
+ client->in_buffer = realloc( client->in_buffer, client->in_buffer_size );
+ if (!client->in_buffer )
{
fprintf(stderr,"HandleSocket Buffer Memory Alloc Error\n");
exit(0);
}
- fprintf(stderr, "Buffer Limit reached realloc new size %d\n", client->buffer_size );
- nb_to_read = client->buffer_size - (client->ptr - client->buffer );
+ fprintf(stderr, "Buffer Limit reached realloc new size %d\n", client->in_buffer_size );
+ nb_to_read = client->in_buffer_size - (client->in_ptr - client->in_buffer );
}
len = sizeof (client->from );
- nb = recvfrom (fd, client->ptr, nb_to_read,0,(struct sockaddr *)&client->from,
+ nb = recvfrom (fd, client->in_ptr, nb_to_read,0,(struct sockaddr *)&client->from,
&len);
if (nb < 0) {
perror(" Read Socket ");
@@ -174,28 +175,28 @@ static void HandleSocket (Channel channel, HANDLE fd, void *data)
IvyChannelClose(client->channel );
return;
}
- client->ptr += nb;
+ client->in_ptr += nb;
if (! client->interpretation )
{
- client->ptr = client->buffer;
+ client->in_ptr = client->in_buffer;
fprintf (stderr,"Socket No interpretation function ??? skipping data\n");
return;
}
- ptr = client->buffer;
+ ptr = client->in_buffer;
- while ( (client->ptr > ptr )&&(ptr_end = (*client->interpretation) (client, client->data, ptr, client->ptr - ptr )))
+ while ( (client->in_ptr > ptr )&&(ptr_end = (*client->interpretation) (client, client->data, ptr, client->in_ptr - ptr )))
{
ptr = ptr_end;
}
- if (ptr < client->ptr )
+ if (ptr < client->in_ptr )
{ /* recopie message incomplet au debut du buffer */
- len = client->ptr - ptr;
- memcpy (client->buffer, ptr, len );
- client->ptr = client->buffer + len;
+ len = client->in_ptr - ptr;
+ memcpy (client->in_buffer, ptr, len );
+ client->in_ptr = client->in_buffer + len;
}
else
{
- client->ptr = client->buffer;
+ client->in_ptr = client->in_buffer;
}
}
static Client CreateClient(int handle)
@@ -208,21 +209,22 @@ static Client CreateClient(int handle)
close ( handle );
exit(0);
}
- client->buffer_size = BUFFER_SIZE;
- client->buffer = malloc( client->buffer_size );
- if (!client->buffer )
+ client->in_buffer_size = BUFFER_SIZE;
+ client->in_buffer = malloc( client->in_buffer_size );
+ if (!client->in_buffer )
{
fprintf(stderr,"HandleSocket Buffer Memory Alloc Error\n");
exit(0);
}
- client->ptr = client->buffer;
+ client->in_ptr = client->in_buffer;
client->out_buffer_size = BUFFER_SIZE;
client->out_buffer = malloc( client->out_buffer_size );
- if (!client->buffer )
+ if (!client->in_buffer )
{
fprintf(stderr,"HandleSocket Buffer Memory Alloc Error\n");
exit(0);
}
+ client->out_ptr = client->out_buffer;
client->fd = handle;
client->channel = IvyChannelOpen (client->fd, client, DeleteSocket, HandleSocket );
@@ -384,55 +386,54 @@ void SocketClose (Client client )
if (client)
IvyChannelClose (client->channel );
}
-
-void SocketSendRaw (Client client, char *buffer, int len )
-{
- int err;
-
- if (!client)
- return;
-
- err = send (client->fd, buffer, len, 0 );
- if (err != len )
- perror ("*** send ***");
-}
-
void SocketSetData (Client client, void *data )
{
if (client)
client->data = data;
}
-void SocketSend (Client client, char *fmt, ... )
+void *SocketGetData (Client client )
{
- int len;
- va_list ap;
+ return client ? client->data : 0;
+}
+void SocketSendBuf (Client client, char *buffer, int len )
+{
+ unsigned long usedspace;
if (!client)
return;
- va_start (ap, fmt );
- len = make_message (&client->out_buffer, &client->out_buffer_size, 0, fmt, ap );
- SocketSendRaw (client, client->out_buffer, len );
- va_end (ap );
+ usedspace = client->out_ptr - client->out_buffer;
+ if ( len >= client->out_buffer_size - usedspace )
+ {
+ /* not enought space */
+ client->out_buffer_size += len - usedspace +1;
+ client->out_buffer = realloc (client->out_buffer, client->out_buffer_size);
+ }
+ memcpy ( client->out_ptr, buffer, len );
+ client->out_ptr += len;
}
-void *SocketGetData (Client client )
-{
- return client ? client->data : 0;
-}
-void SocketSendToAll ( char *fmt, ... )
+void SocketSendFmt (Client client, char *fmt, ... )
{
- Client client;
va_list ap;
- int len;
-
+ if (!client)
+ return;
va_start (ap, fmt );
- len = make_message (&client->out_buffer, &client->out_buffer_size, 0, fmt, ap );
+ client->out_ptr += make_message (&client->out_buffer, &client->out_buffer_size, client->out_ptr - client->out_buffer, fmt, ap );
va_end (ap );
- IVY_LIST_EACH (clients_list, client )
- {
- SocketSendRaw (client, client->out_buffer, len );
- }
+}
+void SocketFlush (Client client)
+{
+ int err;
+ unsigned long len;
+
+ if (!client)
+ return;
+ len = client->out_ptr - client->out_buffer;
+ err = send (client->fd, client->out_buffer, len, 0 );
+ if (err != len )
+ perror ("*** send ***");
+ client->out_ptr = client->out_buffer;
}
/*
diff --git a/src/ivysocket.h b/src/ivysocket.h
index 3d8c991..0f7c99e 100644
--- a/src/ivysocket.h
+++ b/src/ivysocket.h
@@ -69,12 +69,12 @@ extern void SocketServerClose( Server server );
/* Client Part */
extern void SocketKeepAlive( Client client,int keepalive );
extern void SocketClose( Client client );
-extern void SocketSend( Client client, char *fmt, ... );
-extern void SocketSendRaw( Client client, char *buffer, int len );
+extern void SocketSendFmt( Client client, char *fmt, ... );
+extern void SocketSendBuf( Client client, char *buffer, int len );
+extern void SocketFlush (Client client);
extern char *SocketGetPeerHost( Client client );
extern void SocketSetData( Client client, void *data );
extern void *SocketGetData( Client client );
-extern void SocketSendToAll( char *fmt, ... );
extern Client SocketConnect( char * host, unsigned short port,
void *data,
SocketInterpretation interpretation,