Archived
3
0
This commit is contained in:
lapupe 2016-10-28 14:24:15 +02:00
parent b2abfb970e
commit 59db09d6f4
3 changed files with 77 additions and 68 deletions

View File

@ -199,11 +199,13 @@ int srv_get_new_process (char *buf, struct process *p)
int srv_read (const struct service *srv, char ** buf) int srv_read (const struct service *srv, char ** buf)
{ {
//printf("---%s\n", srv->spath);
return file_read (srv->service_fd, buf); return file_read (srv->service_fd, buf);
} }
int srv_write (const struct service *srv, const char * buf, size_t msize) int srv_write (const struct service *srv, const char * buf, size_t msize)
{ {
//printf("---%s\n", srv->spath);
return file_write (srv->service_fd, buf, msize); return file_write (srv->service_fd, buf, msize);
} }
@ -387,11 +389,13 @@ int app_destroy (struct process *p)
int app_read (struct process *p, char ** buf) int app_read (struct process *p, char ** buf)
{ {
//printf("---%s\n", p->path_proc);
return file_read (p->proc_fd, buf); return file_read (p->proc_fd, buf);
} }
int app_write (struct process *p, char * buf, size_t msize) int app_write (struct process *p, char * buf, size_t msize)
{ {
//printf("---%s\n", p->path_proc);
return file_write (p->proc_fd, buf, msize); return file_write (p->proc_fd, buf, msize);
} }

View File

@ -38,7 +38,6 @@ void * pongd_thread(void * pdata) {
if (cfd == -1) if (cfd == -1)
handle_error("accept"); handle_error("accept");
proc->proc_fd = cfd; proc->proc_fd = cfd;
printf("ok\n");
while (1) { while (1) {
if ((nbytes = app_read (proc, &buf)) == -1) { if ((nbytes = app_read (proc, &buf)) == -1) {
@ -56,7 +55,6 @@ void * pongd_thread(void * pdata) {
if ((nbytes = app_write (proc, buf, nbytes)) == -1) { if ((nbytes = app_write (proc, buf, nbytes)) == -1) {
fprintf(stdout, "MAIN_LOOP: error service_write %d\n", nbytes); fprintf(stdout, "MAIN_LOOP: error service_write %d\n", nbytes);
} }
printf("write success\n");
} }
} }

View File

@ -570,6 +570,7 @@ void main_loop (struct service *srv) {
//request //request
info_request tab_req[NBCLIENT]; info_request tab_req[NBCLIENT];
int ret; int ret;
int i;
//pid server //pid server
pthread_t pid_s; pthread_t pid_s;
//pid client //pid client
@ -627,7 +628,9 @@ void main_loop (struct service *srv) {
} }
//printf("Server-select...OK\n"); //printf("Server-select...OK\n");
if(FD_ISSET(listener, &read_fds)) { for (i = 0; i <= fdmax; i++) {
if(FD_ISSET(i, &read_fds)) {
if(i == listener) {
/* handle new connections */ /* handle new connections */
peer_addr_size = sizeof(struct sockaddr_un); peer_addr_size = sizeof(struct sockaddr_un);
newfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size); newfd = accept(sfd, (struct sockaddr *) &peer_addr, &peer_addr_size);
@ -642,17 +645,16 @@ void main_loop (struct service *srv) {
{ /* keep track of the maximum */ { /* keep track of the maximum */
fdmax = newfd; fdmax = newfd;
} }
srv->service_fd = newfd;
} }
} else { } else {
nbytes = srv_read (srv, &buf); nbytes = file_read (i, &buf);
if ( nbytes == -1) { if ( nbytes == -1) {
handle_error("file_read"); handle_error("file_read");
} else if( nbytes == 0) { } else if( nbytes == 0) {
/* close it... */ /* close it... */
close(srv->service_fd); close(i);
/* remove from master set */ /* remove from master set */
FD_CLR(srv->service_fd, &master); FD_CLR(i, &master);
}else { }else {
buf[BUFSIZ - 1] = '\0'; buf[BUFSIZ - 1] = '\0';
printf ("msg received (%d) : %s\n", nbytes, buf); printf ("msg received (%d) : %s\n", nbytes, buf);
@ -693,15 +695,20 @@ void main_loop (struct service *srv) {
} }
} }
} //i == listener
} //if FDISSET
}//boucle for
if (strncmp ("exit", buf, 4) == 0) {
break;
} }
} }//boucle while
if (pthread_cancel(pid_s) != 0) { if (pthread_cancel(pid_s) != 0) {
printf("Aucun thread correspond \n"); printf("Aucun thread correspond \n");
} }
pthread_join(pid_s, NULL); pthread_join(pid_s, NULL);
int i;
/*for (i = 0; i < nbclient; i++) { /*for (i = 0; i < nbclient; i++) {
pthread_join(tab_client[i], NULL); pthread_join(tab_client[i], NULL);
}*/ }*/