mkae compile

This commit is contained in:
Love Hornquist Astrand
2009-11-23 09:19:49 -08:00
parent adb71f15ec
commit 149898ec28

View File

@@ -43,6 +43,8 @@ struct heim_sipc {
void *mech; void *mech;
}; };
#undef HAVE_GCD
#if defined(__APPLE__) && defined(HAVE_GCD) #if defined(__APPLE__) && defined(HAVE_GCD)
#include "heim_ipcServer.h" #include "heim_ipcServer.h"
@@ -464,14 +466,13 @@ add_new_socket(int fd,
void *userctx) void *userctx)
{ {
struct client *c; struct client *c;
int s;
c = calloc(1, sizeof(*c)); c = calloc(1, sizeof(*c));
if (c == NULL) if (c == NULL)
return NULL; return NULL;
c->s = accept(fd, NULL, NULL); c->fd = accept(fd, NULL, NULL);
if(c->s < 0) { if(c->fd < 0) {
free(c); free(c);
return NULL; return NULL;
} }
@@ -504,12 +505,12 @@ socket_complete(heim_sipc_call ctx, int returnvalue, heim_idata *reply)
abort(); abort();
if ((c->flags & WAITING_CLOSE) == 0) { if ((c->flags & WAITING_CLOSE) == 0) {
size_t rlen = reply->length + sizeof(u32) + sizeof(u32);
uint8_t *ptr; uint8_t *ptr;
uint32_t u32; uint32_t u32;
size_t rlen = reply->length + sizeof(u32) + sizeof(u32);
c->obuf = erealloc(c->obuf, c->olen + rlen); c->outmsg = erealloc(c->outmsg, c->olen + rlen);
ptr = &c->omsg[c->olen]; ptr = &c->outmsg[c->olen];
/* length */ /* length */
u32 = htonl(reply->length); u32 = htonl(reply->length);
@@ -533,11 +534,11 @@ socket_complete(heim_sipc_call ctx, int returnvalue, heim_idata *reply)
} }
void static void
process_loop(void) process_loop(void)
{ {
struct pollfd *fds; struct pollfd *fds;
unsigned n, m; unsigned n;
unsigned num_fds; unsigned num_fds;
while(num_clients > 0) { while(num_clients > 0) {
@@ -549,11 +550,11 @@ process_loop(void)
num_fds = num_clients; num_fds = num_clients;
for (n = 0 ; n < num_fds; n++) { for (n = 0 ; n < num_fds; n++) {
fds[n].fd = clients[i]->fd; fds[n].fd = clients[n]->fd;
fds[n].events = 0; fds[n].events = 0;
if (clients[i]->flags & WAITING_READ) if (clients[n]->flags & WAITING_READ)
fds[n].events |= POLLIN; fds[n].events |= POLLIN;
if (clients[i]->flags & WAITING_WRITE) if (clients[n]->flags & WAITING_WRITE)
fds[n].events |= POLLOUT; fds[n].events |= POLLOUT;
fds[n].revents = 0; fds[n].revents = 0;
@@ -570,7 +571,6 @@ process_loop(void)
} }
if (fds[n].revents & POLLIN) { if (fds[n].revents & POLLIN) {
struct socket_call *sc;
ssize_t len; ssize_t len;
uint32_t dlen; uint32_t dlen;
@@ -600,6 +600,7 @@ process_loop(void)
abort(); abort();
while (clients[n]->ptr >= sizeof(dlen)) { while (clients[n]->ptr >= sizeof(dlen)) {
struct socket_call *cs;
memcpy(&dlen, clients[n]->inmsg, sizeof(dlen)); memcpy(&dlen, clients[n]->inmsg, sizeof(dlen));
dlen = ntohl(dlen); dlen = ntohl(dlen);
@@ -607,18 +608,19 @@ process_loop(void)
if (dlen < clients[n]->ptr - sizeof(dlen)) if (dlen < clients[n]->ptr - sizeof(dlen))
break; break;
cs = malloc(sizeof(*cs)); cs = emalloc(sizeof(*cs));
cs->in.data = mallc(dlen); cs->c = clients[n];
memcpy(cs->in.data, clients[i]->inmsg + sizeof(dlen), dlen); cs->in.data = emalloc(dlen);
memcpy(cs->in.data, clients[n]->inmsg + sizeof(dlen), dlen);
cs->in.length = dlen; cs->in.length = dlen;
clients[i]->ptr -= sizeof(dlen) + dlen; clients[n]->ptr -= sizeof(dlen) + dlen;
memmove(clients[i]->inmsg, memmove(clients[n]->inmsg,
clients[i]->inmsg + sizeof(dlen) + dlen, clients[n]->inmsg + sizeof(dlen) + dlen,
clients[i]->ptr); clients[n]->ptr);
c->calls++; clients[n]->calls++;
clients[n]->callback(ctx->userctx, &cs->in, clients[n]->callback(clients[n]->userctx, &cs->in,
NULL, socket_complete, NULL, socket_complete,
(heim_sipc_call)cs); (heim_sipc_call)cs);
} }
@@ -634,7 +636,7 @@ process_loop(void)
continue; continue;
} }
if (clients[n]->olen != len) { if (clients[n]->olen != len) {
memmove(&clients[n]->outmsg[0] memmove(&clients[n]->outmsg[0],
&clients[n]->outmsg[len], &clients[n]->outmsg[len],
clients[n]->olen - len); clients[n]->olen - len);
clients[n]->olen -= len; clients[n]->olen -= len;
@@ -649,7 +651,7 @@ process_loop(void)
} }
n = 0; n = 0;
for (n < num_clients) { while (n < num_clients) {
struct client *c = clients[n]; struct client *c = clients[n];
if ((c->flags & WAITING_CLOSE) == 0 || c->calls) { if ((c->flags & WAITING_CLOSE) == 0 || c->calls) {
n++; n++;
@@ -671,6 +673,7 @@ socket_release(heim_sipc ctx)
{ {
struct client *c = ctx->mech; struct client *c = ctx->mech;
c->flags |= WAITING_CLOSE; c->flags |= WAITING_CLOSE;
return 0;
} }
#endif #endif
@@ -786,3 +789,14 @@ heim_sipc_free_context(heim_sipc ctx)
{ {
(ctx->release)(ctx); (ctx->release)(ctx);
} }
void
heim_ipc_main(void)
{
#if __APPLE__
dispatch_main();
#else
process_loop();
#endif
}