[commit] r13717 - freeswitch/trunk/src/mod/event_handlers/mod_erlang_event
Author: andrew Date: Tue Jun 9 00:24:55 2009 New Revision: 13717 Log: Blindly adding winsock support, I'll test it when I get to a windows machine Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c ============================================================================== --- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c (original) +++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.c Tue Jun 9 00:24:55 2009 @@ -245,7 +245,11 @@ 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 @@ 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 @@ 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 @@ /* 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 @@ close_socket(&l->sockfd); } +#ifdef WIN32 + WSACleanup(); +#endif + switch_mutex_unlock(globals.listener_mutex); switch_sleep(1500000); /* sleep for 1.5 seconds */ Modified: freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h ============================================================================== --- freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h (original) +++ freeswitch/trunk/src/mod/event_handlers/mod_erlang_event/mod_erlang_event.h Tue Jun 9 00:24:55 2009 @@ -143,7 +143,11 @@ 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 @@ 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);
participants (1)
-
FreeSWITCH SVN