Removing printf.
parent
71db43802e
commit
2bba5cb232
|
@ -40,13 +40,6 @@ struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname)
|
||||||
// ipc_add allocate memory then copy the data of srv and pollfd in ctx.
|
// ipc_add allocate memory then copy the data of srv and pollfd in ctx.
|
||||||
TEST_IPC_RR (ipc_add (ctx, &srv, &pollfd), "cannot add the server in the context");
|
TEST_IPC_RR (ipc_add (ctx, &srv, &pollfd), "cannot add the server in the context");
|
||||||
|
|
||||||
#if 0
|
|
||||||
printf ("server init, listen on %ld fd: ", ctx->size);
|
|
||||||
for (size_t i = 0; i < ctx->size; i++)
|
|
||||||
printf (" %d", ctx->pollfd[i].fd);
|
|
||||||
printf ("\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,14 +59,11 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname)
|
||||||
// in order to route requests over any chosen protocol stack
|
// in order to route requests over any chosen protocol stack
|
||||||
// ex: IPC_NETWORK="audio tor://some.example.com/audio ;pong tls://pong.example.com/pong"
|
// ex: IPC_NETWORK="audio tor://some.example.com/audio ;pong tls://pong.example.com/pong"
|
||||||
|
|
||||||
// printf ("IPC_NETWORK: %s\n", networkvar);
|
|
||||||
|
|
||||||
SECURE_BUFFER_DECLARATION (char, columnthensname, BUFSIZ);
|
SECURE_BUFFER_DECLARATION (char, columnthensname, BUFSIZ);
|
||||||
columnthensname[0] = ';';
|
columnthensname[0] = ';';
|
||||||
memcpy (columnthensname + 1, sname, strlen (sname));
|
memcpy (columnthensname + 1, sname, strlen (sname));
|
||||||
|
|
||||||
if (strncmp (networkvar, sname, strlen (sname)) != 0 && strstr (networkvar, columnthensname) == NULL) {
|
if (strncmp (networkvar, sname, strlen (sname)) != 0 && strstr (networkvar, columnthensname) == NULL) {
|
||||||
// printf ("sname %s not found\n", sname);
|
|
||||||
*pfd = 0;
|
*pfd = 0;
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -189,8 +179,6 @@ struct ipc_error ipc_read (const struct ipc_ctx *ctx, uint32_t index, struct ipc
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
size_t msize = IPC_MAX_MESSAGE_SIZE;
|
size_t msize = IPC_MAX_MESSAGE_SIZE;
|
||||||
|
|
||||||
printf ("reading on the fd %d\n", ctx->pollfd[index].fd);
|
|
||||||
|
|
||||||
// On error or closed recipient, the buffer already freed.
|
// On error or closed recipient, the buffer already freed.
|
||||||
TEST_IPC_RETURN_ON_ERROR (usock_recv (ctx->pollfd[index].fd, &buf, &msize));
|
TEST_IPC_RETURN_ON_ERROR (usock_recv (ctx->pollfd[index].fd, &buf, &msize));
|
||||||
TEST_IPC_RETURN_ON_ERROR_FREE (ipc_message_format_read (m, buf, msize), buf);
|
TEST_IPC_RETURN_ON_ERROR_FREE (ipc_message_format_read (m, buf, msize), buf);
|
||||||
|
@ -244,15 +232,10 @@ struct ipc_error ipc_add ( struct ipc_ctx *ctx, struct ipc_connection_info *p, s
|
||||||
T_R ((p == NULL), IPC_ERROR_ADD__NO_PARAM_CLIENT);
|
T_R ((p == NULL), IPC_ERROR_ADD__NO_PARAM_CLIENT);
|
||||||
T_R ((pollfd == NULL), IPC_ERROR_ADD__NO_PARAM_POLLFD);
|
T_R ((pollfd == NULL), IPC_ERROR_ADD__NO_PARAM_POLLFD);
|
||||||
|
|
||||||
printf ("ipc add: add fd %d\n", pollfd[0].fd);
|
|
||||||
|
|
||||||
// Memory reallocation.
|
// Memory reallocation.
|
||||||
ipc_ctx_new_alloc (ctx);
|
ipc_ctx_new_alloc (ctx);
|
||||||
|
|
||||||
if (ctx->size <= 0) {
|
T_R ((ctx->size <= 0), IPC_ERROR_ADD__NOT_ENOUGH_MEMORY);
|
||||||
printf ("ERROR: new alloc <= 0\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
ctx->cinfos[ctx->size - 1] = *p;
|
ctx->cinfos[ctx->size - 1] = *p;
|
||||||
ctx->pollfd[ctx->size - 1] = *pollfd;
|
ctx->pollfd[ctx->size - 1] = *pollfd;
|
||||||
|
@ -336,9 +319,9 @@ struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx
|
||||||
if (txfd == mfd) {
|
if (txfd == mfd) {
|
||||||
TEST_IPC_RR (ipc_write_fd (txfd, m), "cannot send a message to the client");
|
TEST_IPC_RR (ipc_write_fd (txfd, m), "cannot send a message to the client");
|
||||||
|
|
||||||
printf ("Freeing the message\n");
|
// Freeing the message structure.
|
||||||
ipc_message_empty (m);
|
ipc_message_empty (m);
|
||||||
printf ("Removing the message\n");
|
// Removing the message from the context.
|
||||||
ipc_messages_del (&ctx->tx, i); // remove the message indexed by i
|
ipc_messages_del (&ctx->tx, i); // remove the message indexed by i
|
||||||
|
|
||||||
break; // The message has been sent
|
break; // The message has been sent
|
||||||
|
@ -475,20 +458,6 @@ struct ipc_error ipc_events_loop (struct ipc_ctx *ctx, struct ipc_event *event,
|
||||||
|
|
||||||
int32_t n;
|
int32_t n;
|
||||||
|
|
||||||
#if 1
|
|
||||||
printf ("%ld fd for the poll(2) syscall:", ctx->size);
|
|
||||||
for (size_t i = 0; i < ctx->size; i++) {
|
|
||||||
printf (" %d(%d)", ctx->pollfd[i].fd, ctx->pollfd[i].events);
|
|
||||||
}
|
|
||||||
printf ("\n");
|
|
||||||
|
|
||||||
printf ("%ld messages still to write, for fd:", ctx->tx.size);
|
|
||||||
for (size_t i = 0; i < ctx->tx.size; i++) {
|
|
||||||
printf (" %d", ctx->tx.messages[i].fd);
|
|
||||||
}
|
|
||||||
printf ("\n");
|
|
||||||
#endif
|
|
||||||
|
|
||||||
for (size_t i = 0; i < ctx->tx.size; i++) {
|
for (size_t i = 0; i < ctx->tx.size; i++) {
|
||||||
for (size_t y = 0; y < ctx->size; y++) {
|
for (size_t y = 0; y < ctx->size; y++) {
|
||||||
if (ctx->pollfd[y].fd == ctx->tx.messages[i].fd) {
|
if (ctx->pollfd[y].fd == ctx->tx.messages[i].fd) {
|
||||||
|
@ -499,8 +468,7 @@ struct ipc_error ipc_events_loop (struct ipc_ctx *ctx, struct ipc_event *event,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((n = poll(ctx->pollfd, ctx->size, *timer)) < 0) {
|
if ((n = poll(ctx->pollfd, ctx->size, *timer)) < 0) {
|
||||||
printf("select error\n");
|
IPC_RETURN_ERROR (IPC_ERROR_WAIT_EVENT__POLL);
|
||||||
exit(1); // TODO FIXME
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Timeout.
|
// Timeout.
|
||||||
|
|
|
@ -190,8 +190,10 @@ enum ipc_error_code {
|
||||||
, IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100
|
, IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES = 100
|
||||||
, IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101
|
, IPC_ERROR_MESSAGE_DEL__INDEX_ERROR = 101
|
||||||
, IPC_ERROR_MESSAGE_DEL__EMPTY_LIST = 102
|
, IPC_ERROR_MESSAGE_DEL__EMPTY_LIST = 102
|
||||||
, IPC_ERROR_ADD__NO_PARAM_POLLFD = 103
|
, IPC_ERROR_ADD__NO_PARAM_POLLFD = 103
|
||||||
, IPC_ERROR_WRITE__FD_NOT_FOUND = 104
|
, IPC_ERROR_WRITE__FD_NOT_FOUND = 104
|
||||||
|
, IPC_ERROR_ADD__NOT_ENOUGH_MEMORY = 105
|
||||||
|
, IPC_ERROR_WAIT_EVENT__POLL = 106
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ipc_error {
|
struct ipc_error {
|
||||||
|
|
|
@ -173,12 +173,6 @@ struct ipc_error ipc_messages_add (struct ipc_messages *messages, const struct
|
||||||
messages->messages[messages->size -1].payload = NULL;
|
messages->messages[messages->size -1].payload = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message->length > 0 && message->payload != NULL) {
|
|
||||||
printf ("first message payload (%d): %s\n", message->length, message->payload);
|
|
||||||
printf ("second message payload (%d): %s\n"
|
|
||||||
, messages->messages[messages->size - 1].length
|
|
||||||
, messages->messages[messages->size - 1].payload);
|
|
||||||
}
|
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,22 +44,20 @@ void main_loop ()
|
||||||
break;
|
break;
|
||||||
case IPC_EVENT_TYPE_CONNECTION: {
|
case IPC_EVENT_TYPE_CONNECTION: {
|
||||||
cpt++;
|
cpt++;
|
||||||
printf ("connection: %d ctx connected\n", cpt);
|
// printf ("new connection (fd %d): %d ctx connected\n", event.origin, cpt);
|
||||||
printf ("new client has the fd %d\n", event.origin);
|
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case IPC_EVENT_TYPE_DISCONNECTION:
|
case IPC_EVENT_TYPE_DISCONNECTION:
|
||||||
{
|
{
|
||||||
cpt--;
|
cpt--;
|
||||||
printf ("disconnection: %d clients remaining\n", cpt);
|
// printf ("disconnection (fd %d): %d clients remaining\n", event.origin, cpt);
|
||||||
// TODO: something?
|
|
||||||
};
|
};
|
||||||
break;
|
break;
|
||||||
case IPC_EVENT_TYPE_MESSAGE:
|
case IPC_EVENT_TYPE_MESSAGE:
|
||||||
{
|
{
|
||||||
struct ipc_message *m = event.m;
|
struct ipc_message *m = event.m;
|
||||||
if (m->length > 0) {
|
if (m->length > 0) {
|
||||||
printf ("message received (type %d): %.*s\n", m->type, m->length, m->payload);
|
// printf ("message received (type %d): %.*s\n", m->type, m->length, m->payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
m->fd = event.origin;
|
m->fd = event.origin;
|
||||||
|
@ -71,7 +69,7 @@ void main_loop ()
|
||||||
break;
|
break;
|
||||||
case IPC_EVENT_TYPE_TX:
|
case IPC_EVENT_TYPE_TX:
|
||||||
{
|
{
|
||||||
printf ("a message was sent\n");
|
// printf ("a message was sent\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case IPC_EVENT_TYPE_ERROR:
|
case IPC_EVENT_TYPE_ERROR:
|
||||||
|
|
Reference in New Issue