Obsolete
/
libipc-old
Archived
3
0
Fork 0

s/_loop/_poll_event/

more_to_read
Philippe PITTOLI 2018-10-28 19:28:19 +01:00
parent 9c68a6c45d
commit d71640e71b
4 changed files with 20 additions and 35 deletions

View File

@ -199,22 +199,18 @@ int ipc_server_select (struct ipc_clients *clients, struct ipc_service *srv
/* keep track of the biggest file descriptor */ /* keep track of the biggest file descriptor */
fdmax = get_max_fd_from_ipc_clients_ (clients) > srv->service_fd ? get_max_fd_from_ipc_clients_ (clients) : srv->service_fd; fdmax = get_max_fd_from_ipc_clients_ (clients) > srv->service_fd ? get_max_fd_from_ipc_clients_ (clients) : srv->service_fd;
// printf ("loop ipc_server_select main_loop\n");
readf = master; readf = master;
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) { if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
perror("select"); perror("select");
return -1; return -1;
} }
/*run through the existing connections looking for data to be read*/
for (i = 0; i <= fdmax; i++) { for (i = 0; i <= fdmax; i++) {
// printf ("loop ipc_server_select inner loop\n");
if (FD_ISSET(i, &readf)) { if (FD_ISSET(i, &readf)) {
if (i == listener) { if (i == listener) {
*new_connection = 1; *new_connection = 1;
} else { } else {
for(j = 0; j < clients->size; j++) { for(j = 0; j < clients->size; j++) {
// printf ("loop ipc_server_select inner inner loop\n");
if(i == clients->clients[j]->proc_fd ) { if(i == clients->clients[j]->proc_fd ) {
ipc_client_add (active_clients, clients->clients[j]); ipc_client_add (active_clients, clients->clients[j]);
} }
@ -263,19 +259,15 @@ int ipc_application_select (struct ipc_services *services, struct ipc_services *
/* keep track of the biggest file descriptor */ /* keep track of the biggest file descriptor */
fdmax = get_max_fd_from_ipc_services_ (services); fdmax = get_max_fd_from_ipc_services_ (services);
// printf ("loop ipc_server_select main_loop\n");
readf = master; readf = master;
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) { if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
perror("select"); perror("select");
return -1; return -1;
} }
/*run through the existing connections looking for data to be read*/
for (i = 0; i <= fdmax; i++) { for (i = 0; i <= fdmax; i++) {
// printf ("loop ipc_server_select inner loop\n");
if (FD_ISSET(i, &readf)) { if (FD_ISSET(i, &readf)) {
for(j = 0; j < services->size; j++) { for(j = 0; j < services->size; j++) {
// printf ("loop ipc_server_select inner inner loop\n");
if(i == services->services[j]->service_fd ) { if(i == services->services[j]->service_fd ) {
ipc_service_add (active_services, services->services[j]); ipc_service_add (active_services, services->services[j]);
} }
@ -308,7 +300,7 @@ int handle_new_connection (struct ipc_service *srv
return 0; return 0;
} }
int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
, struct ipc_event *event) , struct ipc_event *event)
{ {
assert (clients != NULL); assert (clients != NULL);
@ -338,16 +330,13 @@ int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv
/* keep track of the biggest file descriptor */ /* keep track of the biggest file descriptor */
fdmax = get_max_fd_from_ipc_clients_ (clients) > srv->service_fd ? get_max_fd_from_ipc_clients_ (clients) : srv->service_fd; fdmax = get_max_fd_from_ipc_clients_ (clients) > srv->service_fd ? get_max_fd_from_ipc_clients_ (clients) : srv->service_fd;
// printf ("loop ipc_server_select main_loop\n");
readf = master; readf = master;
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) { if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
perror("select"); perror("select");
return -1; return -1;
} }
/*run through the existing connections looking for data to be read*/
for (i = 0; i <= fdmax; i++) { for (i = 0; i <= fdmax; i++) {
// printf ("loop ipc_server_select inner loop\n");
if (FD_ISSET(i, &readf)) { if (FD_ISSET(i, &readf)) {
if (i == listener) { if (i == listener) {
// connection // connection
@ -372,7 +361,7 @@ int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv
struct ipc_client *pc = clients->clients[j]; struct ipc_client *pc = clients->clients[j];
ret = ipc_server_read (pc, m); ret = ipc_server_read (pc, m);
if (ret < 0) { if (ret < 0) {
handle_err ("ipc_service_loop", "ipc_server_read < 0"); handle_err ("ipc_service_poll_event", "ipc_server_read < 0");
ipc_message_empty (m); ipc_message_empty (m);
free (m); free (m);
@ -383,10 +372,10 @@ int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv
// disconnection: close the client then delete it from clients // disconnection: close the client then delete it from clients
if (ret == 1) { if (ret == 1) {
if (ipc_server_close_client (pc) < 0) { if (ipc_server_close_client (pc) < 0) {
handle_err( "ipc_service_loop", "ipc_server_close_client < 0"); handle_err( "ipc_service_poll_event", "ipc_server_close_client < 0");
} }
if (ipc_client_del (clients, pc) < 0) { if (ipc_client_del (clients, pc) < 0) {
handle_err( "ipc_service_loop", "ipc_client_del < 0"); handle_err( "ipc_service_poll_event", "ipc_client_del < 0");
} }
ipc_message_empty (m); ipc_message_empty (m);
free (m); free (m);
@ -409,7 +398,7 @@ int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv
return 0; return 0;
} }
int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *event, int interactive) int ipc_application_poll_event_ (struct ipc_services *services, struct ipc_event *event, int interactive)
{ {
assert (services != NULL); assert (services != NULL);
@ -438,16 +427,13 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
/* keep track of the biggest file descriptor */ /* keep track of the biggest file descriptor */
fdmax = get_max_fd_from_ipc_services_ (services); fdmax = get_max_fd_from_ipc_services_ (services);
// printf ("loop ipc_server_select main_loop\n");
readf = master; readf = master;
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) { if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
perror("select"); perror("select");
return -1; return -1;
} }
/*run through the existing connections looking for data to be read*/
for (i = 0; i <= fdmax; i++) { for (i = 0; i <= fdmax; i++) {
// printf ("loop ipc_server_select inner loop\n");
if (FD_ISSET(i, &readf)) { if (FD_ISSET(i, &readf)) {
// interactive: input on stdin // interactive: input on stdin
@ -466,7 +452,6 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
} }
for(j = 0; j < services->size; j++) { for(j = 0; j < services->size; j++) {
// printf ("loop ipc_server_select inner inner loop\n");
if(i == services->services[j]->service_fd ) { if(i == services->services[j]->service_fd ) {
// listen to what they have to say (disconnection or message) // listen to what they have to say (disconnection or message)
// then add a client to `event`, the ipc_event structure // then add a client to `event`, the ipc_event structure
@ -482,7 +467,7 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
struct ipc_service *ps = services->services[j]; struct ipc_service *ps = services->services[j];
ret = ipc_application_read (ps, m); ret = ipc_application_read (ps, m);
if (ret < 0) { if (ret < 0) {
handle_err ("ipc_application_loop", "ipc_application_read < 0"); handle_err ("ipc_application_poll_event", "ipc_application_read < 0");
ipc_message_empty (m); ipc_message_empty (m);
free (m); free (m);
@ -493,10 +478,10 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
// disconnection: close the service // disconnection: close the service
if (ret == 1) { if (ret == 1) {
if (ipc_application_close (ps) < 0) { if (ipc_application_close (ps) < 0) {
handle_err( "ipc_application_loop", "ipc_application_close < 0"); handle_err( "ipc_application_poll_event", "ipc_application_close < 0");
} }
if (ipc_service_del (services, ps) < 0) { if (ipc_service_del (services, ps) < 0) {
handle_err( "ipc_application_loop", "ipc_service_del < 0"); handle_err( "ipc_application_poll_event", "ipc_service_del < 0");
} }
ipc_message_empty (m); ipc_message_empty (m);
free (m); free (m);
@ -519,10 +504,10 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
return 0; return 0;
} }
int ipc_application_loop (struct ipc_services *services, struct ipc_event *event) { int ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event) {
return ipc_application_loop_ (services, event, 0); return ipc_application_poll_event_ (services, event, 0);
} }
int ipc_application_loop_interactive (struct ipc_services *services, struct ipc_event *event) { int ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event) {
return ipc_application_loop_ (services, event, 1); return ipc_application_poll_event_ (services, event, 1);
} }

View File

@ -33,7 +33,7 @@ int ipc_server_write (const struct ipc_client *, const struct ipc_message *m);
int ipc_server_select (struct ipc_clients * clients, struct ipc_service *srv int ipc_server_select (struct ipc_clients * clients, struct ipc_service *srv
, struct ipc_clients *active_clients, int *new_connection); , struct ipc_clients *active_clients, int *new_connection);
int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv int ipc_service_poll_event (struct ipc_clients *clients, struct ipc_service *srv
, struct ipc_event *event); , struct ipc_event *event);
// APPLICATION // APPLICATION
@ -51,7 +51,7 @@ int ipc_application_write (struct ipc_service *, const struct ipc_message *m);
int ipc_application_select (struct ipc_services *services, struct ipc_services *active_services); int ipc_application_select (struct ipc_services *services, struct ipc_services *active_services);
int ipc_application_loop (struct ipc_services *services, struct ipc_event *event); int ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event);
int ipc_application_loop_interactive (struct ipc_services *services, struct ipc_event *event); int ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event);
#endif #endif

View File

@ -75,10 +75,10 @@ void interactive (char *env[])
while (1) { while (1) {
printf ("msg to send: "); printf ("msg to send: ");
fflush (stdout); fflush (stdout);
ret = ipc_application_loop_interactive (&services, &event); ret = ipc_application_peek_event (&services, &event);
if (ret != 0) { if (ret != 0) {
handle_error("ipc_application_loop != 0"); handle_error("ipc_application_peek_event != 0");
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }

View File

@ -25,11 +25,11 @@ void main_loop ()
event.type = IPC_EVENT_TYPE_NOT_SET; event.type = IPC_EVENT_TYPE_NOT_SET;
while(1) { while(1) {
// ipc_service_loop provides one event at a time // ipc_service_poll_event provides one event at a time
// warning: event->m is free'ed if not NULL // warning: event->m is free'ed if not NULL
ret = ipc_service_loop (clients, srv, &event); ret = ipc_service_poll_event (clients, srv, &event);
if (ret != 0) { if (ret != 0) {
handle_error("ipc_service_loop != 0"); handle_error("ipc_service_poll_event != 0");
// the application will shut down, and close the service // the application will shut down, and close the service
if (ipc_server_close (srv) < 0) { if (ipc_server_close (srv) < 0) {
handle_error("ipc_server_close < 0"); handle_error("ipc_server_close < 0");