Obsolete
/
libipc-old
Archived
3
0
Fork 0

default cb_out OK

pollfd
Karchnu 2020-07-08 13:51:32 +02:00
parent 0a8680a7e8
commit 553a550d97
1 changed files with 15 additions and 8 deletions

View File

@ -221,7 +221,21 @@ default_cb_in(int fd, struct ipc_message *m)
enum ipccb
default_cb_out(int fd, struct ipc_message *m)
{
printf("TODO: default_cb_out\n");
size_t msize = 0;
SECURE_DECLARATION (struct ipc_error, ret);
SECURE_BUFFER_DECLARATION (char, buf, IPC_MAX_MESSAGE_SIZE);
char *pbuf = buf;
ipc_message_format_write (m, &pbuf, &msize);
size_t nbytes_sent = 0;
ret = usock_send (fd, buf, msize, &nbytes_sent);
// On error or if what was sent != what should have been sent.
if (ret.error_code != IPC_ERROR_NONE || nbytes_sent != msize) {
return IPC_CB_FD_ERROR;
}
return IPC_CB_NO_ERROR;
}
@ -236,7 +250,6 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
// read and write automatically and provide a new IPC_EVENT_TYPE indicating the switch.
T_R ((ctx->switchdb.size == 0), IPC_ERROR_FD_SWITCHING__NO_FD_RECORD);
printf ("coucou\n");
int talkingfd = ctx->pollfd[index].fd;
int dest_fd = -1;
struct ipc_switching sw;
@ -248,7 +261,6 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
is_valid = ipc_switching_get_ (&ctx->switchdb, talkingfd, &sw);
T_R ((is_valid == -1), IPC_ERROR_FD_SWITCHING__NO_FD_RECORD);
printf ("valid\n");
if (sw.orig == talkingfd) {
dest_fd = sw.dest;
@ -268,7 +280,6 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
r = (*sw.dest_in)(talkingfd, &m);
}
}
printf ("cb done\n");
// Message reception OK: reading the message and put it in the list of messages to send.
if (r == IPC_CB_NO_ERROR) {
@ -282,8 +293,6 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
IPC_RETURN_NO_ERROR;
}
printf ("error or disconnection\n");
/**
* NOTE: In any other case, the fd is, or should be closed.
*/
@ -299,11 +308,9 @@ struct ipc_error fd_switching_read (struct ipc_event *event, struct ipc_ctx *ctx
// 2. set event (either error or disconnection)
if (r == IPC_CB_FD_CLOSING) {
printf ("DISCONNECTION\n");
IPC_EVENT_SET (event, IPC_EVENT_TYPE_DISCONNECTION, index, talkingfd, NULL);
}
else {
printf ("ERROR\n");
IPC_EVENT_SET (event, IPC_EVENT_TYPE_ERROR, index, talkingfd, NULL);
}