Skip to content
Browse files

acceptConnection now has a functionPointer

upon connection accept, will not use the functionPointer to spawn a
thread to handle the request (John has to write this part)
  • Loading branch information...
1 parent 0e4feca commit aacff56cf5d05f33c2998132b21bab7a08e76508 @MrTyton MrTyton committed Oct 6, 2012
Showing with 29 additions and 3 deletions.
  1. +2 −1 socket.c
  2. +5 −2 socket.h
  3. +22 −0 socket.h~
View
3 socket.c
@@ -25,7 +25,7 @@ int connectToServer(int sock, int port, char * name) { /*creates an outgoing con
return 1;
}
-int acceptConnection(int sock) { /*accepts an inbound connection on the specified socket. This function should not return unless broken from, or gives an error (such as a fail listen or fail accept). Upon accepting the new connection, a new socket is created to work with.*/
+int acceptConnection(int sock, int(* functionPointer)(int)) { /*accepts an inbound connection on the specified socket. This function should not return unless broken from, or gives an error (such as a fail listen or fail accept). Upon accepting the new connection, a new socket is created to work with.*/
socklen_t alen;
struct sockaddr_in my_addr;
struct sockaddr_in client_addr;
@@ -44,6 +44,7 @@ int acceptConnection(int sock) { /*accepts an inbound connection on the specifie
return -2;
}
/*INSERT NEW THREAD HERE FOR THE SOCKET TO TALK TO - USE ACCEPTEDSOCKET*/
+ /*JOHN FINISH THIS OUT, USE THE FUNCTIONPOINTER PASSED INTO ACCEPTCONNECTION TO SPAWN THE THREAD*/
}
}
return 0;
View
7 socket.h
@@ -3,11 +3,14 @@
#include <stdlib.h>
#include <stdio.h>
#include <netdb.h>
+#include <pthread.h>
-int openSocket(int port);
-int connectToServer(int sock, int port, char * name);
+int (* functionPointer) (int) = NULL; /*generic function pointer, accepts a socket*/
+int openSocket(int port); /*This creates a generic socket, that performs asynchronously, using whatever address the machine wants to give it, on the port given*/
+int connectToServer(int sock, int port, char * name); /*creates an outgoing connection, using the given socket, the port of the away machine, and the IP address (e.g. 198.162.2.2) of the remote machine. Returns 0 on failure, 1 on success*/
+int acceptConnection(int sock, int(* functionPointer)(int)); /*accepts an inbound connection on the specified socket, with a function for it to call upon accept. This function should not return unless broken from, or gives an error (such as a fail listen or fail accept). Upon accepting the new connection, a new socket is created to work with.*/
/**Continuously reads from the tap and prints the string it gets from tap
* Takes no parameters
View
22 socket.h~
@@ -0,0 +1,22 @@
+#include <sys/socket.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <netdb.h>
+
+
+int openSocket(int port);
+int connectToServer(int sock, int port, char * name);
+
+
+/**Continuously reads from the tap and prints the string it gets from tap
+ * Takes no parameters
+ * Will take up to 500 bytes from tap otherwise segmentation fault,
+ * but the 500 bytes is adjustable
+ * Exits entire program if for some reason program can't open tap*/
+char * read();
+
+/**Writes messages into the tap
+ * There are no parameters
+ Exits entire program if for some reason program can't open tap*/
+char * write(char *msg);

0 comments on commit aacff56

Please sign in to comment.
Something went wrong with that request. Please try again.