FS-3621 --resolve

This commit is contained in:
Anthony Minessale 2011-10-20 10:19:39 -05:00
parent 7d639c271c
commit 6bbde4e27f
1 changed files with 27 additions and 6 deletions

View File

@ -1095,7 +1095,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_event_socket_load)
static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout) static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout)
{ {
switch_size_t mlen, bytes = 0; switch_size_t mlen, bytes = 0;
char mbuf[2048] = ""; char *mbuf = NULL;
char buf[1024] = ""; char buf[1024] = "";
switch_size_t len; switch_size_t len;
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
@ -1105,16 +1105,20 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
void *pop; void *pop;
char *ptr; char *ptr;
uint8_t crcount = 0; uint8_t crcount = 0;
uint32_t max_len = sizeof(mbuf); uint32_t max_len = 10485760, block_len = 2048, buf_len = 0;
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
int clen = 0; int clen = 0;
*event = NULL; *event = NULL;
if (prefs.done) { if (prefs.done) {
return SWITCH_STATUS_FALSE; switch_goto_status(SWITCH_STATUS_FALSE, end);
} }
switch_zmalloc(mbuf, block_len);
switch_assert(mbuf);
buf_len = block_len;
start = switch_epoch_time_now(NULL); start = switch_epoch_time_now(NULL);
ptr = mbuf; ptr = mbuf;
@ -1126,10 +1130,24 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
uint8_t do_sleep = 1; uint8_t do_sleep = 1;
mlen = 1; mlen = 1;
if (bytes == buf_len - 1) {
char *tmp;
int pos;
pos = (ptr - mbuf);
buf_len += block_len;
tmp = realloc(mbuf, buf_len);
switch_assert(tmp);
mbuf = tmp;
memset(mbuf + bytes, 0, buf_len - bytes);
ptr = (mbuf + pos);
}
status = switch_socket_recv(listener->sock, ptr, &mlen); status = switch_socket_recv(listener->sock, ptr, &mlen);
if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) { if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
return SWITCH_STATUS_FALSE; switch_goto_status(SWITCH_STATUS_FALSE, end);
} }
if (mlen) { if (mlen) {
@ -1198,7 +1216,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) { if (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
free(body); free(body);
return SWITCH_STATUS_FALSE; switch_goto_status(SWITCH_STATUS_FALSE, end);
} }
/* /*
@ -1230,7 +1248,7 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
elapsed = (uint32_t) (switch_epoch_time_now(NULL) - start); elapsed = (uint32_t) (switch_epoch_time_now(NULL) - start);
if (elapsed >= timeout) { if (elapsed >= timeout) {
switch_clear_flag_locked(listener, LFLAG_RUNNING); switch_clear_flag_locked(listener, LFLAG_RUNNING);
return SWITCH_STATUS_FALSE; switch_goto_status(SWITCH_STATUS_FALSE, end);
} }
} }
@ -1354,6 +1372,9 @@ static switch_status_t read_packet(listener_t *listener, switch_event_t **event,
} }
} }
end:
//switch_safe_free(mbuf);
return status; return status;
} }