/* Receive RTSP message through RTSP connection */ static apt_bool_t rtsp_client_poller_signal_process(void *obj, const apr_pollfd_t *descriptor) { rtsp_client_t *client = obj; rtsp_client_connection_t *rtsp_connection = descriptor->client_data; apr_status_t status; apr_size_t offset; apr_size_t length; apt_text_stream_t *stream; rtsp_message_t *message; apt_message_status_e msg_status; if(!rtsp_connection || !rtsp_connection->sock) { return FALSE; } stream = &rtsp_connection->rx_stream; /* calculate offset remaining from the previous receive / if any */ offset = stream->pos - stream->text.buf; /* calculate available length */ length = sizeof(rtsp_connection->rx_buffer) - 1 - offset; status = apr_socket_recv(rtsp_connection->sock,stream->pos,&length); if(status == APR_EOF || length == 0) { return rtsp_client_on_disconnect(client,rtsp_connection); } /* calculate actual length of the stream */ stream->text.length = offset + length; stream->pos[length] = '\0'; apt_log(RTSP_LOG_MARK,APT_PRIO_INFO,"Receive RTSP Data %s [%"APR_SIZE_T_FMT" bytes]\n%s", rtsp_connection->id, length, stream->pos); /* reset pos */ apt_text_stream_reset(stream); do { msg_status = rtsp_parser_run(rtsp_connection->parser,stream,&message); if(rtsp_client_message_handler(rtsp_connection,message,msg_status) == FALSE) { return FALSE; } } while(apt_text_is_eos(stream) == FALSE); /* scroll remaining stream */ apt_text_stream_scroll(stream); return TRUE; }
/* Receive RTSP message through RTSP connection */ static apt_bool_t rtsp_client_message_receive(apt_net_client_task_t *task, apt_net_client_connection_t *connection) { rtsp_client_t *client = apt_net_client_task_object_get(task); rtsp_client_connection_t *rtsp_connection; apr_status_t status; apr_size_t offset; apr_size_t length; apt_text_stream_t *stream; if(!connection || !connection->sock) { return FALSE; } rtsp_connection = connection->obj; stream = &rtsp_connection->rx_stream; /* init length of the stream */ stream->text.length = sizeof(rtsp_connection->rx_buffer)-1; /* calculate offset remaining from the previous receive / if any */ offset = stream->pos - stream->text.buf; /* calculate available length */ length = stream->text.length - offset; status = apr_socket_recv(connection->sock,stream->pos,&length); if(status == APR_EOF || length == 0) { return rtsp_client_on_disconnect(client,rtsp_connection); } /* calculate actual length of the stream */ stream->text.length = offset + length; stream->pos[length] = '\0'; apt_log(APT_LOG_MARK,APT_PRIO_INFO,"Receive RTSP Stream %s [%lu bytes]\n%s", connection->id, length, stream->pos); /* reset pos */ stream->pos = stream->text.buf; /* walk through the stream parsing RTSP messages */ return rtsp_stream_walk(rtsp_connection->parser,stream,rtsp_client_message_handler,rtsp_connection); }