static gboolean io_session_event(GIOChannel *chan, GIOCondition cond, gpointer data) { sdp_pdu_hdr_t hdr; uint8_t *buf; int sk, len, size; if (cond & G_IO_NVAL) return FALSE; sk = g_io_channel_unix_get_fd(chan); if (cond & (G_IO_HUP | G_IO_ERR)) { sdp_svcdb_collect_all(sk); return FALSE; } len = recv(sk, &hdr, sizeof(sdp_pdu_hdr_t), MSG_PEEK); if (len != sizeof(sdp_pdu_hdr_t)) { sdp_svcdb_collect_all(sk); return FALSE; } size = sizeof(sdp_pdu_hdr_t) + ntohs(hdr.plen); buf = malloc(size); if (!buf) return TRUE; len = recv(sk, buf, size, 0); /* Check here only that the received message is not empty. * Incorrect length of message should be processed later * inside handle_request() in order to produce ErrorResponse. */ if (len <= 0) { sdp_svcdb_collect_all(sk); free(buf); return FALSE; } handle_request(sk, buf, len); return TRUE; }
static gboolean io_session_event(GIOChannel *chan, GIOCondition cond, gpointer data) { sdp_pdu_hdr_t hdr; uint8_t *buf; int sk, len, size; if (cond & G_IO_NVAL) return FALSE; sk = g_io_channel_unix_get_fd(chan); if (cond & (G_IO_HUP | G_IO_ERR)) { sdp_svcdb_collect_all(sk); return FALSE; } len = recv(sk, &hdr, sizeof(sdp_pdu_hdr_t), MSG_PEEK); if (len <= 0) { sdp_svcdb_collect_all(sk); return FALSE; } size = sizeof(sdp_pdu_hdr_t) + ntohs(hdr.plen); buf = malloc(size); if (!buf) return TRUE; len = recv(sk, buf, size, 0); if (len <= 0) { sdp_svcdb_collect_all(sk); free(buf); return FALSE; } handle_request(sk, buf, len); return TRUE; }