From: erubow Date: Thu, 8 Mar 2007 02:26:12 +0000 (+0000) Subject: The two important functions in this file were already copied to dstmserver.c X-Git-Tag: preEdgeChange~674 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=390df8cf09b07db3354e68af221af4a60a41d876;p=IRC.git The two important functions in this file were already copied to dstmserver.c --- diff --git a/Robust/src/Runtime/DSTM/interface/server.c b/Robust/src/Runtime/DSTM/interface/server.c deleted file mode 100644 index 1f7774fa..00000000 --- a/Robust/src/Runtime/DSTM/interface/server.c +++ /dev/null @@ -1,105 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define LISTEN_PORT 2153 -#define BACKLOG 10 //max pending connections -#define RECIEVE_BUFFER_SIZE 1500 - -void *dstm_listen(); -void *dstm_accept(void *); - -int main() -{ - pthread_t thread_listen; - - pthread_create(&thread_listen, NULL, dstm_listen, NULL); - - pthread_join(thread_listen, NULL); - return 0; -} - -void *dstm_listen() -{ - int listenfd, acceptfd; - struct sockaddr_in my_addr; - struct sockaddr_in client_addr; - socklen_t addrlength = sizeof(struct sockaddr); - pthread_t thread_dstm_accept; - int i; - - listenfd = socket(PF_INET, SOCK_STREAM, 0); - if (listenfd == -1) - { - perror("socket"); - exit(1); - } - - my_addr.sin_family = AF_INET; - my_addr.sin_port = htons(LISTEN_PORT); - my_addr.sin_addr.s_addr = INADDR_ANY; - memset(&(my_addr.sin_zero), '\0', 8); - - if (bind(listenfd, (struct sockaddr *)&my_addr, addrlength) == -1) - { - perror("bind"); - exit(1); - } - - if (listen(listenfd, BACKLOG) == -1) - { - perror("listen"); - exit(1); - } - - printf("Listening on port %d, fd = %d\n", LISTEN_PORT, listenfd); - while(1) - { - acceptfd = accept(listenfd, (struct sockaddr *)&client_addr, &addrlength); - pthread_create(&thread_dstm_accept, NULL, dstm_accept, (void *)acceptfd); - } - pthread_exit(NULL); -} - -void *dstm_accept(void *acceptfd) -{ - int numbytes; - char buffer[RECIEVE_BUFFER_SIZE]; - int fd_flags = fcntl((int)acceptfd, F_GETFD); - printf("Recieved connection: fd = %d\n", (int)acceptfd); - do - { - numbytes = recv((int)acceptfd, (void *)buffer, sizeof(buffer), 0); - buffer[numbytes] = '\0'; - if (numbytes == -1) - { - perror("recv"); - pthread_exit(NULL); - } - else - { - printf("Read %d bytes from %d\n", numbytes, (int)acceptfd); - printf("%s", buffer); - } - - } while (numbytes != 0); - if (close((int)acceptfd) == -1) - { - perror("close"); - pthread_exit(NULL); - } - else - printf("Closed connection: fd = %d\n", (int)acceptfd); - pthread_exit(NULL); -} - - -