]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Blindly adding winsock support, I'll test it when I get to a windows machine
authorAndrew Thompson <andrew@hijacked.us>
Tue, 9 Jun 2009 05:24:55 +0000 (05:24 +0000)
committerAndrew Thompson <andrew@hijacked.us>
Tue, 9 Jun 2009 05:24:55 +0000 (05:24 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13717 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c
src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h

index 261c2a9a61df34691a79f86d7d9576f3d6d4836d..9f7df236075d1ef403c59f2ab71944e09568f37f 100644 (file)
@@ -245,7 +245,11 @@ static void close_socket(int *sock)
        switch_mutex_lock(listen_list.sock_mutex);
        if (*sock) {
                shutdown(*sock, SHUT_RDWR);
+#ifdef WIN32
+               closesocket(*sock);
+#else
                close(*sock);
+#endif
                sock = NULL;
        }
        switch_mutex_unlock(listen_list.sock_mutex);
@@ -1020,7 +1024,11 @@ static listener_t* new_outbound_listener(char* node)
        int clientfd;
 
        if (SWITCH_STATUS_SUCCESS==initialise_ei(&ec)) {
+#ifdef WIN32
+               WSASetLastError(0);
+#else
                errno = 0;
+#endif
                if ((clientfd=ei_connect(&ec,node)) < 0) {
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error connecting to node %s (erl_errno=%d, errno=%d)!\n",node,erl_errno,errno);
                        return NULL;
@@ -1404,6 +1412,23 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
        int on = 1;
        int clientfd;
        int epmdfd;
+#ifdef WIN32
+       /* borrowed from MSDN, stupid winsock */
+       WORD wVersionRequested;
+       WSADATA wsaData;
+
+       wVersionRequested = MAKEWORD(2, 2);
+       
+       if (WSAStartup(wVersionRequested, &wsaData) != 0) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Winsock initialization failed, oh well\n");
+               return SWITCH_STATUS_TERM;
+       }
+
+       if (LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
+               switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Your winsock version doesn't support the 2.2 specification, bailing\n");
+               return SWITCH_STATUS_TERM;
+       }
+#endif
 
        memset(&listen_list, 0, sizeof(listen_list));
        config();
@@ -1488,7 +1513,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
                /* zero out errno because ei_accept doesn't differentiate between a
                 * failed authentication or a socket failure, or a client version
                 * mismatch or a godzilla attack */
+#ifdef WIN32
+               WSASetLastError(0);
+#else
                errno = 0;
+#endif
                if ((clientfd = ei_accept_tmo(&ec, listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
                        if (prefs.done) {
                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Shutting Down\n");
@@ -1570,6 +1599,10 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_erlang_event_shutdown)
                close_socket(&l->sockfd);
        }
 
+#ifdef WIN32
+       WSACleanup();
+#endif
+
        switch_mutex_unlock(globals.listener_mutex);
 
        switch_sleep(1500000); /* sleep for 1.5 seconds */
index 72c208b8c6e2d93ef85db7cd33de291cf74f0fc5..248b773aa361e0961c45b9d71f2a0eef588fd265 100644 (file)
@@ -143,7 +143,11 @@ struct globals_struct {
 typedef struct globals_struct globals_t;
 
 struct listen_list_struct {
+#ifdef WIN32
+       SOCKET sockfd;
+#else
        int sockfd;
+#endif
        switch_mutex_t *sock_mutex;
        listener_t *listeners;
        uint8_t ready;
@@ -216,6 +220,10 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec);
                break; \
 }
 
+#ifdef WIN32 /* MSDN suggested hack to fake errno for network operations */
+#define errno WSAGetLastError()
+#endif
+
 /* mod_erlang_event.c */
 session_elem_t* attach_call_to_registered_process(listener_t* listener, char* reg_name, switch_core_session_t *session);
 session_elem_t* attach_call_to_pid(listener_t* listener, erlang_pid* pid, switch_core_session_t *session);