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