start of windows port

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10899 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2008-12-21 22:13:20 +00:00
parent 1bda469485
commit 65b9fe8e8b
3 changed files with 26 additions and 14 deletions

View File

@ -32,13 +32,16 @@
*/ */
#include <esl.h> #include <esl.h>
#ifndef WIN32
#define closesocket(x) close(x)
#endif
#ifndef HAVE_GETHOSTBYNAME_R #ifndef HAVE_GETHOSTBYNAME_R
extern int gethostbyname_r (const char *__name, extern int gethostbyname_r (const char *__name,
struct hostent *__result_buf, struct hostent *__result_buf,
char *__buf, size_t __buflen, char *__buf, size_t __buflen,
struct hostent **__result, struct hostent **__result,
int *__h_errnop); int *__h_errnump);
#endif #endif
@ -440,7 +443,7 @@ esl_status_t esl_listen(const char *host, esl_port_t port, esl_listen_callback_t
end: end:
if (server_sock != ESL_SOCK_INVALID) { if (server_sock != ESL_SOCK_INVALID) {
close(server_sock); closesocket(server_sock);
server_sock = ESL_SOCK_INVALID; server_sock = ESL_SOCK_INVALID;
} }
@ -474,14 +477,14 @@ esl_status_t esl_connect(esl_handle_t *handle, const char *host, esl_port_t port
memset(&handle->hostent, 0, sizeof(handle->hostent)); memset(&handle->hostent, 0, sizeof(handle->hostent));
#ifdef HAVE_GETHOSTBYNAME_R_FIVE #ifdef HAVE_GETHOSTBYNAME_R_FIVE
rval = gethostbyname_r(host, &handle->hostent, handle->hostbuf, sizeof(handle->hostbuf), &handle->errno); rval = gethostbyname_r(host, &handle->hostent, handle->hostbuf, sizeof(handle->hostbuf), &handle->errnum);
result = handle->hostent; result = handle->hostent;
#else #else
rval = gethostbyname_r(host, &handle->hostent, handle->hostbuf, sizeof(handle->hostbuf), &result, &handle->errno); rval = gethostbyname_r(host, &handle->hostent, handle->hostbuf, sizeof(handle->hostbuf), &result, &handle->errnum);
#endif #endif
if (rval) { if (rval) {
strerror_r(handle->errno, handle->err, sizeof(handle->err)); strerror_r(handle->errnum, handle->err, sizeof(handle->err));
goto fail; goto fail;
} }
@ -546,7 +549,7 @@ esl_status_t esl_disconnect(esl_handle_t *handle)
} }
if (handle->sock != ESL_SOCK_INVALID) { if (handle->sock != ESL_SOCK_INVALID) {
close(handle->sock); closesocket(handle->sock);
handle->sock = ESL_SOCK_INVALID; handle->sock = ESL_SOCK_INVALID;
return ESL_SUCCESS; return ESL_SUCCESS;
} }
@ -604,7 +607,7 @@ esl_status_t esl_recv_event(esl_handle_t *handle, esl_event_t **save_event)
char *hname, *hval; char *hname, *hval;
char *col; char *col;
char *cl; char *cl;
ssize_t len; esl_ssize_t len;
int zc = 0; int zc = 0;
esl_mutex_lock(handle->mutex); esl_mutex_lock(handle->mutex);
@ -625,7 +628,7 @@ esl_status_t esl_recv_event(esl_handle_t *handle, esl_event_t **save_event)
return ESL_FAIL; return ESL_FAIL;
} }
} else if (rrval < 0) { } else if (rrval < 0) {
strerror_r(handle->errno, handle->err, sizeof(handle->err)); strerror_r(handle->errnum, handle->err, sizeof(handle->err));
goto fail; goto fail;
} else { } else {
zc = 0; zc = 0;
@ -685,7 +688,7 @@ esl_status_t esl_recv_event(esl_handle_t *handle, esl_event_t **save_event)
do { do {
esl_ssize_t r; esl_ssize_t r;
if ((r = recv(handle->sock, body + sofar, len - sofar, 0)) < 0) { if ((r = recv(handle->sock, body + sofar, len - sofar, 0)) < 0) {
strerror_r(handle->errno, handle->err, sizeof(handle->err)); strerror_r(handle->errnum, handle->err, sizeof(handle->err));
goto fail; goto fail;
} }
sofar += r; sofar += r;
@ -717,7 +720,7 @@ esl_status_t esl_recv_event(esl_handle_t *handle, esl_event_t **save_event)
char *hname, *hval; char *hname, *hval;
char *col; char *col;
char *cl; char *cl;
ssize_t len; esl_ssize_t len;
char *c; char *c;
esl_event_safe_destroy(&handle->last_ievent); esl_event_safe_destroy(&handle->last_ievent);
@ -775,7 +778,7 @@ esl_status_t esl_recv_event(esl_handle_t *handle, esl_event_t **save_event)
do { do {
esl_ssize_t r; esl_ssize_t r;
if ((r = recv(handle->sock, body + sofar, len - sofar, 0)) < 0) { if ((r = recv(handle->sock, body + sofar, len - sofar, 0)) < 0) {
strerror_r(handle->errno, handle->err, sizeof(handle->err)); strerror_r(handle->errnum, handle->err, sizeof(handle->err));
goto fail; goto fail;
} }
sofar += r; sofar += r;

View File

@ -214,19 +214,24 @@ int esl_config_get_cas_bits(char *strvalue, unsigned char *outbits)
char cas_bits[5]; char cas_bits[5];
unsigned char bit = 0x8; unsigned char bit = 0x8;
char *double_colon = strchr(strvalue, ':'); char *double_colon = strchr(strvalue, ':');
int x = 0;
if (!double_colon) { if (!double_colon) {
esl_log(ESL_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon); esl_log(ESL_LOG_ERROR, "No CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon);
return -1; return -1;
} }
double_colon++; double_colon++;
*outbits = 0; *outbits = 0;
cas_bits[4] = 0; cas_bits[4] = 0;
if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) { if (sscanf(double_colon, "%c%c%c%c", &cas_bits[0], &cas_bits[1], &cas_bits[2], &cas_bits[3]) != 4) {
esl_log(ESL_LOG_ERROR, "Invalid CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon); esl_log(ESL_LOG_ERROR, "Invalid CAS bits specified: %s, :xxxx definition expected, where x is 1 or 0\n", double_colon);
return -1; return -1;
} }
esl_log(ESL_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits); esl_log(ESL_LOG_DEBUG, "CAS bits specification found: %s\n", cas_bits);
int x = 0;
for (; cas_bits[x]; x++) { for (; cas_bits[x]; x++) {
if ('1' == cas_bits[x]) { if ('1' == cas_bits[x]) {
*outbits |= bit; *outbits |= bit;

View File

@ -153,9 +153,11 @@ typedef struct esl_event esl_event_t;
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifndef WIN32
#include <sys/signal.h> #include <sys/signal.h>
#include <unistd.h> #include <unistd.h>
#include <ctype.h> #include <ctype.h>
#endif
#ifdef HAVE_STRINGS_H #ifdef HAVE_STRINGS_H
#include <strings.h> #include <strings.h>
@ -168,8 +170,9 @@ typedef struct esl_event esl_event_t;
#define esl_strlen_zero_buf(s) (*(s) == '\0') #define esl_strlen_zero_buf(s) (*(s) == '\0')
#ifdef WIN32 #ifdef WIN32
#include <winsock2.h>
#include <windows.h> #include <windows.h>
typedef HANDLE esl_socket_t; typedef SOCKET esl_socket_t;
typedef unsigned __int64 uint64_t; typedef unsigned __int64 uint64_t;
typedef unsigned __int32 uint32_t; typedef unsigned __int32 uint32_t;
typedef unsigned __int16 uint16_t; typedef unsigned __int16 uint16_t;
@ -180,6 +183,7 @@ typedef __int16 int16_t;
typedef __int8 int8_t; typedef __int8 int8_t;
typedef intptr_t esl_ssize_t; typedef intptr_t esl_ssize_t;
typedef int esl_filehandle_t; typedef int esl_filehandle_t;
#define ESL_SOCK_INVALID INVALID_SOCKET
#else #else
#include <stdint.h> #include <stdint.h>
#include <sys/types.h> #include <sys/types.h>
@ -211,7 +215,7 @@ typedef struct {
char hostbuf[256]; char hostbuf[256];
esl_socket_t sock; esl_socket_t sock;
char err[256]; char err[256];
int errno; int errnum;
char header_buf[4196]; char header_buf[4196];
char last_reply[1024]; char last_reply[1024];
char last_sr_reply[1024]; char last_sr_reply[1024];