Index: ColonetServer.cpp
===================================================================
--- ColonetServer.cpp	(revision 22)
+++ ColonetServer.cpp	(revision 23)
@@ -14,10 +14,11 @@
 #include <errno.h>
 #include <arpa/inet.h>
 
+#include <fcntl.h>
+
 #include <colonet_wireless.h>
 
 #include "includes/ColonetServer.h"
-#include "includes/initialization.h"
 #include "includes/ConnectionPool.h"
 #include "includes/client.h"
 #include "includes/options.h"
@@ -28,7 +29,9 @@
 
 ConnectionPool * connection_pool;
 ColonetWireless* wireless;
+int listenSocket = 0;
 
+
 ColonetServer::ColonetServer(): logger("logFile.txt") {
 }
 
@@ -51,27 +54,7 @@
   return 0;
 }
 
-int ColonetServer::initialize_wireless()
-{
-  char* log_filename = NULL;
 
-  if (optionsG.logging_enabled) {
-    log_filename = optionsG.log_filename;
-  }
-
-  wireless = new ColonetWireless(optionsG.wireless_port, 
-                                 wirelessMessageHandler, log_filename, 
-                                 /*!optionsG.listener_mode*/false, true);
-  //Note: last arg set to true ignores token ring;  in general, this should
-  //probably be false (changed for demo purposes)
-
-  if (!wireless->run_listener_thread()) {
-		return -1;
-	}
-
-	return 0;
-}
-
 int ColonetServer::log_error(char * error_message) {
   return logger.logMessage(LOG_TYPE_ERROR, error_message);
 }
@@ -80,9 +63,6 @@
   return logger.logMessage(LOG_TYPE_MESSAGE, message);
 }
 
-int listenSocket = 0;
-//ConnectionPool connection_pool;
-
 //TODO: make it so the log file name is passed in on command line and default it to something if it isn't
 //Log logger("logFile.txt");
 
@@ -181,4 +161,134 @@
   return &connection_pool;
 }
 
+int ColonetServer::initialize_wireless()
+{
+  char* log_filename = NULL;
 
+  if (optionsG.logging_enabled) {
+    log_filename = optionsG.log_filename;
+  }
+
+  wireless = new ColonetWireless(optionsG.wireless_port, 
+                                 wirelessMessageHandler, log_filename, 
+                                 /*!optionsG.listener_mode*/false, true);
+  //Note: last arg set to true ignores token ring;  in general, this should
+  //probably be false (changed for demo purposes)
+
+  if (!wireless->run_listener_thread()) {
+		return -1;
+	}
+
+	return 0;
+}
+
+int ColonetServer::initConnection(int port)
+{
+  printf("Initializing connection that will be used to listen for " 
+         "clients...\n");
+  int opts = 1;
+  struct sockaddr_in my_addr;
+
+  //get a socket fd
+  if ((listenSocket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
+    printf("\tThere was an error creating a socket\n");
+    return -1;
+  }
+
+  //set up the address struct
+  memset(&my_addr,'\0',sizeof(my_addr));
+  my_addr.sin_family = AF_INET;
+  my_addr.sin_addr.s_addr = htonl(INADDR_ANY);
+  my_addr.sin_port = htons(port);
+  
+  setsockopt(listenSocket, SOL_SOCKET, SO_REUSEADDR, &opts, sizeof(opts));
+
+  //get the current socket options
+  if ((opts = fcntl(listenSocket, F_GETFL)) < 0) {
+    printf("\tThere was an error getting the socket options.\n");
+    return -1;
+  }
+
+  //set the socket to non blocking
+  opts = (opts | O_NONBLOCK);
+  if (fcntl(listenSocket, F_SETFL, opts) < 0) {
+    printf("\tThere was an error setting the socket to be non blocking.\n");
+    return -1;
+  }
+  
+  //bind the socket to listen on the specified port
+  if (bind(listenSocket, (struct sockaddr *) &my_addr, sizeof(my_addr)) < 0) {
+    printf("\tThere was an error binding the socket\n");
+    return -1;
+  }
+  
+  return 0;
+}
+
+//this is old code that was commented out that I didn't want to delete yet
+/*
+int parseCommandLine(int argc, char * argv[], commandParams_t * params)
+{
+  printf("Parsing Command Line...\n");
+  if (!params)
+    return -1;
+
+  //if no command line parameters were specified, set to defaults
+  if (argc == 1) {
+    printf("No port was specified for listening for client connections."
+           "  Defaulting to %d\n", DEFAULTPORT);
+    params->listenPort = DEFAULTPORT;
+  }
+
+  if (!argv)
+    return -1;
+
+  int i;
+  for (i = 1; i < argc; i++) {
+    char * temp = argv[i];
+    if (temp[0] != '-')
+      {
+        printUsage(argv[0]);
+        return -1;
+      }
+
+    switch(temp[1])
+      {
+      case 'h': printUsage(argv[0]);
+        break;
+      case 'p': 
+        {
+          if (i >= argc-1)
+            {
+              printUsage(argv[0]);
+              return -1;
+            }
+          i++;
+          char * portString = argv[i];
+          char * endptr = NULL;
+          int port = strtol(portString, &endptr, 10);
+          if (*endptr != '\0')
+            {
+              printf("Invalid port specified...%s, %d\n", endptr, port);
+              return -1;
+            }
+          if (port < SMALLEST_POSS_LISTEN_PORT)
+            {
+              printf("You cannot listen on a port less than %d.\n",
+                     SMALLEST_POSS_LISTEN_PORT);
+              return -1;
+            }
+          params->listenPort = port;
+          printf("Setting port to listen on to %d.\n", params->listenPort);
+        }
+        break;
+      default: printUsage(argv[0]);
+        return -1;
+        break;
+      }
+  }
+
+  return 0;
+}
+*/
+
