char * receive_string( SOCKET connected_socket) { char buf[BUF_LEN]; receive_line( connected_socket, buf); return strdup(buf); }
char * receive_string( SOCKET connected_socket) { char buf[BUF_LEN]; /* MM FIXME: there is a nasty bug here, size of buf if BUF_LEN which is never indicated to downstream receive_line */ receive_line( connected_socket, buf); return strdup(buf); }
SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; gboolean stop = FALSE; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\n') { /* End of line */ stop = receive_line(sdi); break; } } } if (sr_sw_limits_check(&devc->limits) || stop) sr_dev_acquisition_stop(sdi); else dispatch(sdi); return TRUE; }
SR_PRIV int agdmm_receive_data(int fd, int revents, void *cb_data) { struct sr_dev_inst *sdi; struct dev_context *devc; struct sr_serial_dev_inst *serial; int len; (void)fd; if (!(sdi = cb_data)) return TRUE; if (!(devc = sdi->priv)) return TRUE; serial = sdi->conn; if (revents == G_IO_IN) { /* Serial data arrived. */ while (AGDMM_BUFSIZE - devc->buflen - 1 > 0) { len = serial_read_nonblocking(serial, devc->buf + devc->buflen, 1); if (len < 1) break; devc->buflen += len; *(devc->buf + devc->buflen) = '\0'; if (*(devc->buf + devc->buflen - 1) == '\n') { /* End of line */ receive_line(sdi); break; } } } dispatch(sdi); if (devc->limit_samples && devc->num_samples >= devc->limit_samples) sdi->driver->dev_acquisition_stop(sdi, cb_data); return TRUE; }
status_t HTTPStream::receive_header(int *http_status) { *http_status = -1; mHeaders.clear(); char line[2048]; status_t err = receive_line(line, sizeof(line)); if (err != OK) { return err; } mHeaders.add(string(kStatusKey), string(line)); char *spacePos = strchr(line, ' '); if (spacePos == NULL) { // Malformed response? return UNKNOWN_ERROR; } char *status_start = spacePos + 1; char *status_end = status_start; while (isdigit(*status_end)) { ++status_end; } if (status_end == status_start) { // Malformed response, status missing? return UNKNOWN_ERROR; } memmove(line, status_start, status_end - status_start); line[status_end - status_start] = '\0'; long tmp = strtol(line, NULL, 10); if (tmp < 0 || tmp > 999) { return UNKNOWN_ERROR; } *http_status = (int)tmp; for (;;) { err = receive_line(line, sizeof(line)); if (err != OK) { return err; } if (*line == '\0') { // Empty line signals the end of the header. break; } // puts(line); char *colonPos = strchr(line, ':'); if (colonPos == NULL) { mHeaders.add(string(line), string()); } else { char *end_of_key = colonPos; while (end_of_key > line && isspace(end_of_key[-1])) { --end_of_key; } char *start_of_value = colonPos + 1; while (isspace(*start_of_value)) { ++start_of_value; } *end_of_key = '\0'; mHeaders.add(string(line), string(start_of_value)); } } return OK; }