|
|
|
@ -199,22 +199,18 @@ int ipc_server_select (struct ipc_clients *clients, struct ipc_service *srv
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
|
|
// printf ("loop ipc_server_select main_loop\n");
|
|
|
|
|
readf = master;
|
|
|
|
|
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
|
|
|
|
|
perror("select");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*run through the existing connections looking for data to be read*/
|
|
|
|
|
for (i = 0; i <= fdmax; i++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner loop\n");
|
|
|
|
|
if (FD_ISSET(i, &readf)) {
|
|
|
|
|
if (i == listener) {
|
|
|
|
|
*new_connection = 1;
|
|
|
|
|
} else {
|
|
|
|
|
for(j = 0; j < clients->size; j++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner inner loop\n");
|
|
|
|
|
if(i == clients->clients[j]->proc_fd ) {
|
|
|
|
|
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 */
|
|
|
|
|
fdmax = get_max_fd_from_ipc_services_ (services);
|
|
|
|
|
|
|
|
|
|
// printf ("loop ipc_server_select main_loop\n");
|
|
|
|
|
readf = master;
|
|
|
|
|
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
|
|
|
|
|
perror("select");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*run through the existing connections looking for data to be read*/
|
|
|
|
|
for (i = 0; i <= fdmax; i++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner loop\n");
|
|
|
|
|
if (FD_ISSET(i, &readf)) {
|
|
|
|
|
for(j = 0; j < services->size; j++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner inner loop\n");
|
|
|
|
|
if(i == services->services[j]->service_fd ) {
|
|
|
|
|
ipc_service_add (active_services, services->services[j]);
|
|
|
|
|
}
|
|
|
|
@ -308,7 +300,7 @@ int handle_new_connection (struct ipc_service *srv
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
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 */
|
|
|
|
|
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;
|
|
|
|
|
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
|
|
|
|
|
perror("select");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*run through the existing connections looking for data to be read*/
|
|
|
|
|
for (i = 0; i <= fdmax; i++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner loop\n");
|
|
|
|
|
if (FD_ISSET(i, &readf)) {
|
|
|
|
|
if (i == listener) {
|
|
|
|
|
// connection
|
|
|
|
@ -372,7 +361,7 @@ int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv
|
|
|
|
|
struct ipc_client *pc = clients->clients[j];
|
|
|
|
|
ret = ipc_server_read (pc, m);
|
|
|
|
|
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);
|
|
|
|
|
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
|
|
|
|
|
if (ret == 1) {
|
|
|
|
|
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) {
|
|
|
|
|
handle_err( "ipc_service_loop", "ipc_client_del < 0");
|
|
|
|
|
handle_err( "ipc_service_poll_event", "ipc_client_del < 0");
|
|
|
|
|
}
|
|
|
|
|
ipc_message_empty (m);
|
|
|
|
|
free (m);
|
|
|
|
@ -409,7 +398,7 @@ int ipc_service_loop (struct ipc_clients *clients, struct ipc_service *srv
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
@ -438,16 +427,13 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
|
|
|
|
|
/* keep track of the biggest file descriptor */
|
|
|
|
|
fdmax = get_max_fd_from_ipc_services_ (services);
|
|
|
|
|
|
|
|
|
|
// printf ("loop ipc_server_select main_loop\n");
|
|
|
|
|
readf = master;
|
|
|
|
|
if(select(fdmax+1, &readf, NULL, NULL, NULL) == -1) {
|
|
|
|
|
perror("select");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*run through the existing connections looking for data to be read*/
|
|
|
|
|
for (i = 0; i <= fdmax; i++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner loop\n");
|
|
|
|
|
if (FD_ISSET(i, &readf)) {
|
|
|
|
|
|
|
|
|
|
// 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++) {
|
|
|
|
|
// printf ("loop ipc_server_select inner inner loop\n");
|
|
|
|
|
if(i == services->services[j]->service_fd ) {
|
|
|
|
|
// listen to what they have to say (disconnection or message)
|
|
|
|
|
// 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];
|
|
|
|
|
ret = ipc_application_read (ps, m);
|
|
|
|
|
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);
|
|
|
|
|
free (m);
|
|
|
|
|
|
|
|
|
@ -493,10 +478,10 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
|
|
|
|
|
// disconnection: close the service
|
|
|
|
|
if (ret == 1) {
|
|
|
|
|
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) {
|
|
|
|
|
handle_err( "ipc_application_loop", "ipc_service_del < 0");
|
|
|
|
|
handle_err( "ipc_application_poll_event", "ipc_service_del < 0");
|
|
|
|
|
}
|
|
|
|
|
ipc_message_empty (m);
|
|
|
|
|
free (m);
|
|
|
|
@ -519,10 +504,10 @@ int ipc_application_loop_ (struct ipc_services *services, struct ipc_event *even
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ipc_application_loop (struct ipc_services *services, struct ipc_event *event) {
|
|
|
|
|
return ipc_application_loop_ (services, event, 0);
|
|
|
|
|
int ipc_application_poll_event (struct ipc_services *services, struct ipc_event *event) {
|
|
|
|
|
return ipc_application_poll_event_ (services, event, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int ipc_application_loop_interactive (struct ipc_services *services, struct ipc_event *event) {
|
|
|
|
|
return ipc_application_loop_ (services, event, 1);
|
|
|
|
|
int ipc_application_peek_event (struct ipc_services *services, struct ipc_event *event) {
|
|
|
|
|
return ipc_application_poll_event_ (services, event, 1);
|
|
|
|
|
}
|
|
|
|
|