static switch_status_t read_packet(listener_t *listener, switch_event_t **event, uint32_t timeout)
{
switch_size_t mlen, bytes = 0;
- char mbuf[2048] = "";
+ char *mbuf = NULL;
char buf[1024] = "";
switch_size_t len;
switch_status_t status = SWITCH_STATUS_SUCCESS;
void *pop;
char *ptr;
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;
int clen = 0;
*event = NULL;
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);
ptr = mbuf;
uint8_t do_sleep = 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);
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 (prefs.done || (!SWITCH_STATUS_IS_BREAK(status) && status != SWITCH_STATUS_SUCCESS)) {
free(body);
- return SWITCH_STATUS_FALSE;
+ switch_goto_status(SWITCH_STATUS_FALSE, end);
}
/*
elapsed = (uint32_t) (switch_epoch_time_now(NULL) - start);
if (elapsed >= timeout) {
switch_clear_flag_locked(listener, LFLAG_RUNNING);
- return SWITCH_STATUS_FALSE;
+ switch_goto_status(SWITCH_STATUS_FALSE, end);
}
}
}
}
+ end:
+
+ //switch_safe_free(mbuf);
return status;
}