Add Stack
This commit is contained in:
parent
5518f3eea7
commit
6c181cdbc4
1 changed files with 15 additions and 1 deletions
16
src/server.c
16
src/server.c
|
@ -3,7 +3,10 @@
|
|||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "server.h"
|
||||
#include "common.h"
|
||||
|
@ -20,6 +23,7 @@ struct client_details clients[MAX_CLIENTS];
|
|||
|
||||
int main(int argc, char *argv[]) {
|
||||
int server_port, serv_sockid, client_sockid, client_id;
|
||||
int stack[2];
|
||||
int message_pipe[2];
|
||||
struct sockaddr_in server_socket;
|
||||
struct sockaddr_in client_socket;
|
||||
|
@ -81,6 +85,11 @@ int main(int argc, char *argv[]) {
|
|||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (pipe(stack) != 0){
|
||||
fprintf(stderr, "ERROR : failed to create stack pipe\n");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
if (pthread_create(&dispatcher, NULL, Dispatcher, NULL) != 0) {
|
||||
fprintf(stderr, "pthread_create: error for Dispatcher\n");
|
||||
exit(EXIT_FAILURE);
|
||||
|
@ -135,6 +144,9 @@ int main(int argc, char *argv[]) {
|
|||
disconnect_client(i);
|
||||
}
|
||||
|
||||
close(stack[0]);
|
||||
close(stack[1]);
|
||||
|
||||
printf("Server end, closing connection\n");
|
||||
(void) pthread_join(dispatcher, &retval);
|
||||
close(serv_sockid);
|
||||
|
@ -221,7 +233,9 @@ void *ClientListener(void *arg) {
|
|||
while (1) {
|
||||
/* Read n bytes at a time, because we don't know how long the message will be */
|
||||
while ((n = read(details.sockid, buf, BUF_LEN)) > 0) {
|
||||
// TODO: do somethig with the stream (push to global stack?)
|
||||
/* TODO: Get mutex */
|
||||
write(stack[1], buf, n);
|
||||
/* TODO: Free mutex */
|
||||
}
|
||||
if (n < 0) {
|
||||
fprintf(stderr, "ERROR: read\n");
|
||||
|
|
Loading…
Reference in a new issue