some work on event selector

This commit is contained in:
Cedric Roux
2016-05-01 22:43:36 +02:00
parent e6d5f22c8b
commit c3e59b16b3
10 changed files with 275 additions and 64 deletions
+44
View File
@@ -3,6 +3,7 @@
#include <stdlib.h>
#include <pthread.h>
#include <time.h>
#include <unistd.h>
void new_thread(void *(*f)(void *), void *data)
{
@@ -59,3 +60,46 @@ list *list_append(list *l, void *data)
l->last = new;
return l;
}
/****************************************************************************/
/* socket */
/****************************************************************************/
void socket_send(int socket, void *buffer, int size)
{
char *x = buffer;
int ret;
while (size) {
ret = write(socket, x, size);
if (ret <= 0) abort();
size -= ret;
x += ret;
}
}
/****************************************************************************/
/* buffer */
/****************************************************************************/
void PUTC(OBUF *o, char c)
{
if (o->osize == o->omaxsize) {
o->omaxsize += 512;
o->obuf = realloc(o->obuf, o->omaxsize);
if (o->obuf == NULL) abort();
}
o->obuf[o->osize] = c;
o->osize++;
}
void PUTS(OBUF *o, char *s)
{
while (*s) PUTC(o, *s++);
}
void PUTI(OBUF *o, int i)
{
char s[64];
sprintf(s, "%d", i);
PUTS(o, s);
}