Add sorta working win32 support

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13764 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Andrew Thompson 2009-06-11 22:29:37 +00:00
parent 942269648d
commit b32ea95f68
5 changed files with 346 additions and 21 deletions

View File

@ -143,9 +143,9 @@ int ei_pid_from_rpc(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *mo
/* function to spawn a process on a remote node */
int ei_spawn(struct ei_cnode_s *ec, int sockfd, erlang_ref *ref, char *module, char *function, int argc, char **argv)
{
int i;
ei_x_buff buf;
ei_x_new_with_version(&buf);
int i;
ei_x_encode_tuple_header(&buf, 3);
ei_x_encode_atom(&buf, "$gen_call");
@ -323,7 +323,7 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec)
memset(&server_addr, 0, sizeof(server_addr));
/* convert the configured IP to network byte order, handing errors */
rv = inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
if (rv == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip);
return SWITCH_STATUS_FALSE;
@ -336,7 +336,11 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec)
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(prefs.port);
if ((nodehost = gethostbyaddr(&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
#ifdef WIN32
if ((nodehost = gethostbyaddr((const char*)&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
#else
if ((nodehost = gethostbyaddr((const char*)&server_addr.sin_addr.s_addr, sizeof(server_addr.sin_addr.s_addr), AF_INET)))
#endif
memcpy(thishostname, nodehost->h_name, EI_MAXHOSTNAMELEN);
if (switch_strlen_zero_buf(thishostname)) {

View File

@ -79,10 +79,11 @@ static void *SWITCH_THREAD_FUNC api_exec(switch_thread_t *thread, void *obj)
switch_event_t *event;
if (switch_event_create(&event, SWITCH_EVENT_BACKGROUND_JOB) == SWITCH_STATUS_SUCCESS) {
ei_x_buff ebuf;
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-UUID", acs->uuid_str);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Job-Command", acs->api_cmd);
ei_x_buff ebuf;
ei_x_new_with_version(&ebuf);
if (acs->arg) {
@ -250,20 +251,22 @@ static switch_status_t handle_msg_event(listener_t *listener, int arity, ei_x_bu
else {
int custom = 0;
switch_event_types_t type;
int i = 0;
if (!switch_test_flag(listener, LFLAG_EVENTS)) {
switch_set_flag_locked(listener, LFLAG_EVENTS);
}
for (int i = 1; i < arity; i++) {
for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
if (custom) {
switch_core_hash_insert(listener->event_hash, atom, MARKER);
} else if (switch_name_event(atom, &type) == SWITCH_STATUS_SUCCESS) {
if (type == SWITCH_EVENT_ALL) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ALL events enabled\n");
uint32_t x = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "ALL events enabled\n");
for (x = 0; x < SWITCH_EVENT_ALL; x++) {
listener->event_list[x] = 1;
}
@ -295,9 +298,10 @@ static switch_status_t handle_msg_nixevent(listener_t *listener, int arity, ei_x
}
else {
int custom = 0;
int i = 0;
switch_event_types_t type;
for (int i = 1; i < arity; i++) {
for (i = 1; i < arity; i++) {
if (!ei_decode_atom(buf->buff, &buf->index, atom)) {
if (custom) {

View File

@ -0,0 +1,299 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="9.00"
Name="mod_erlang_event"
ProjectGUID="{024864AC-0022-45F0-AB06-915C3E2C0FF1}"
RootNamespace="mod_erlang_event"
Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms>
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/I &quot;C:\Program Files\erl5.7.1\lib\erl_interface-3.6.1\include&quot; /D &quot;WIN32&quot; /D &quot;__WIN32__&quot;"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="&quot;C:\cygwin\home\andrew\otp_src_R13B01\lib\erl_interface\obj.debug\win32/ei.lib&quot; /NODEFAULTLIB:libcmt"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalOptions="/I &quot;C:\Program Files\erl5.7.1\lib\erl_interface-3.6.1\include&quot; /D &quot;WIN32&quot; /D &quot;__WIN32__&quot;"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalOptions="&quot;C:\cygwin\home\andrew\otp_src_R13B01\lib\erl_interface\obj.debug\win32/ei.lib&quot;"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Debug|x64"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_debug.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|x64"
ConfigurationType="2"
InheritedPropertySheets="..\..\..\..\w32\module_release.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
UsePrecompiledHeader="0"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="$(SolutionDir)$(PlatformName)\$(ConfigurationName)/mod/$(ProjectName).dll"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
TargetMachine="17"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\ei_helpers.c"
>
</File>
<File
RelativePath=".\handle_msg.c"
>
</File>
<File
RelativePath=".\mod_erlang_event.c"
>
</File>
<File
RelativePath=".\mod_erlang_event.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -240,14 +240,19 @@ static void event_handler(switch_event_t *event)
}
#ifdef WIN32
static void close_socket(SOCKET *sock)
#else
static void close_socket(int *sock)
#endif
{
switch_mutex_lock(listen_list.sock_mutex);
if (*sock) {
shutdown(*sock, SHUT_RDWR);
#ifdef WIN32
shutdown(*sock, SD_BOTH);
closesocket(*sock);
#else
shutdown(*sock, SHUT_RDWR);
close(*sock);
#endif
sock = NULL;
@ -357,21 +362,22 @@ session_elem_t * find_session_elem_by_pid(listener_t *listener, erlang_pid *pid)
static switch_xml_t erlang_fetch(const char *sectionstr, const char *tag_name, const char *key_name, const char *key_value,
switch_event_t *params, void *user_data)
{
switch_xml_t xml = NULL;
struct erlang_binding *ptr;
switch_uuid_t uuid;
char uuid_str[SWITCH_UUID_FORMATTED_LENGTH+1];
int type, size;
int i = 0;
void *p = NULL;
char *xmlstr;
struct erlang_binding *ptr;
switch_uuid_t uuid;
switch_xml_section_t section;
switch_xml_t xml = NULL;
ei_x_buff *rep;
ei_x_buff buf;
ei_x_new_with_version(&buf);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "looking for bindings\n");
switch_xml_section_t section = switch_xml_parse_section_string((char *) sectionstr);
section = switch_xml_parse_section_string((char *) sectionstr);
for (ptr = bindings.head; ptr && ptr->section != section; ptr = ptr->next); /* just get the first match */
@ -459,6 +465,7 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t *
switch_core_session_t *session;
switch_event_t *call_event=NULL;
switch_channel_t *channel=NULL;
ei_x_buff lbuf;
/* Send a message to the associated registered process to let it know there is a call.
Message is a tuple of the form {call, <call-event>}
@ -480,7 +487,6 @@ static switch_status_t notify_new_session(listener_t *listener, session_elem_t *
switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Content-Type", "command/reply");
switch_event_add_header_string(call_event, SWITCH_STACK_BOTTOM, "Reply-Text", "+OK\n");
ei_x_buff lbuf;
ei_x_new_with_version(&lbuf);
ei_x_encode_tuple_header(&lbuf, 2);
ei_x_encode_atom(&lbuf, "call");
@ -709,11 +715,10 @@ static void listener_main_loop(listener_t *listener)
while ((status >= 0 || erl_errno == ETIMEDOUT || erl_errno == EAGAIN) && !prefs.done) {
erlang_msg msg;
ei_x_buff buf;
ei_x_new(&buf);
ei_x_buff rbuf;
ei_x_new(&buf);
ei_x_new_with_version(&rbuf);
/* do we need the mutex when reading? */
@ -1464,7 +1469,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
memset(&server_addr, 0, sizeof(server_addr));
/* convert the configured IP to network byte order, handing errors */
rv = inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
rv = switch_inet_pton(AF_INET, prefs.ip, &server_addr.sin_addr.s_addr);
if (rv == 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not parse invalid ip address: %s\n", prefs.ip);
goto init_failed;
@ -1485,7 +1490,11 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
goto sock_fail;
}
#ifdef WIN32
if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, (const char *)&on, sizeof(on))) {
#else
if (setsockopt(listen_list.sockfd, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on))) {
#endif
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to enable SO_REUSEADDR for socket on %s:%u : %s\n", prefs.ip, prefs.port, strerror(errno));
goto sock_fail;
}
@ -1500,7 +1509,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
goto sock_fail;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket up listening on %s:%u\n", prefs.ip, prefs.port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Socket %d up listening on %s:%u\n", listen_list.sockfd, prefs.ip, prefs.port);
break;
sock_fail:
switch_yield(100000);
@ -1538,13 +1547,18 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
#else
errno = 0;
#endif
if ((clientfd = ei_accept_tmo(&ec, listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
if ((clientfd = ei_accept_tmo(&ec, (int)listen_list.sockfd, &conn, 100)) == ERL_ERROR) {
if (prefs.done) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Shutting Down\n");
} else if (erl_errno == ETIMEDOUT) {
continue;
#ifdef WIN32
} else if (WSAGetLastError()) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error %d %d\n", erl_errno, WSAGetLastError());
#else
} else if (errno) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Socket Error %d %d\n", erl_errno, errno);
#endif
} else {
/* if errno didn't get set, assume nothing *too* horrible occured */
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
@ -1557,7 +1571,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_erlang_event_runtime)
listener = new_listener(&ec,clientfd);
if (listener) {
/* store the IP and node name we are talking with */
inet_ntop(AF_INET, conn.ipadr, listener->remote_ip, sizeof(listener->remote_ip));
switch_inet_ntop(AF_INET, conn.ipadr, listener->remote_ip, sizeof(listener->remote_ip));
listener->peer_nodename = switch_core_strdup(listener->pool,conn.nodename);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Launching listener, connection from node %s, ip %s\n", conn.nodename, listener->remote_ip);

View File

@ -81,7 +81,11 @@ typedef enum {
5 call sessions will be "attached" to the same listener.
*/
struct listener {
#ifdef WIN32
SOCKET sockfd;
#else
int sockfd;
#endif
struct ei_cnode_s *ec;
struct erlang_process log_process;
struct erlang_process event_process;
@ -221,7 +225,7 @@ switch_status_t initialise_ei(struct ei_cnode_s *ec);
}
#ifdef WIN32 /* MSDN suggested hack to fake errno for network operations */
#define errno WSAGetLastError()
/*#define errno WSAGetLastError()*/
#endif
/* mod_erlang_event.c */