static int process_server_input(int fd, struct xmpp *xmpp) { char buf[BUF_BYTES]; int n, remain; do { n = io_recv(sizeof(buf), buf, &remain, &fd); if (n <= 0) return -1; if (xmpp_process_input(n, buf, xmpp, xmpp)) return -1; } while (remain > 0); return 0; }
ssize_t buffer_recv(struct buffer *buf, int sockfd, size_t size, int flags) { size_t count; ssize_t len; void *end; end = buffer_end(buf); count = buffer_remaining(buf); if (count > size) count = size; len = io_recv(sockfd, end, count, flags); if (len < 0) return len; buf->end += len; return len; }
static int process_server_input(int fd, struct xmpp *xmpp) { char buf[DATA_BUF]; int n, remain; do { n = io_recv(sizeof(buf), buf, &remain, &fd); if (n < 0) { print_msg(0, "", "; error: reading from socket (remain: %d)\n", remain); return -1; } log_printf(20, "; processing state: '%d' buf: '%.*s'\n", xmpp->xml.state, n, buf); if (xmpp_process_input(n, buf, xmpp, xmpp)) { print_msg(0, "", "; error: processing xmpp xml\n"); log_printf(20, "; state: '%d' buf: '%.*s'\n", xmpp->xml.state, n, buf); return -1; } } while (remain > 0); return 0; }
static int tcp_server_client_recv(object_t parent) { return io_recv(parent); }
void PX4IO::task_main() { ASSERT(_fd == -1); log("ready"); /* open the serial port */ _fd = ::open("/dev/ttyS2", O_RDWR | O_NONBLOCK); if (_fd < 0) { debug("failed to open serial port for IO: %d", errno); _task = -1; _exit(errno); } /* protocol stream */ _io_stream = hx_stream_init(_fd, &PX4IO::rx_callback_trampoline, this); perf_counter_t pc_tx_bytes = perf_alloc(PC_COUNT, "PX4IO frames transmitted"); perf_counter_t pc_rx_bytes = perf_alloc(PC_COUNT, "PX4IO frames received"); perf_counter_t pc_rx_errors = perf_alloc(PC_COUNT, "PX4IO receive errors"); hx_stream_set_counters(_io_stream, pc_tx_bytes, pc_rx_bytes, pc_rx_errors); /* poll descriptor(s) */ struct pollfd fds[1]; fds[0].fd = _fd; fds[0].events = POLLIN; /* loop handling received serial bytes */ while (!_task_should_exit) { /* sleep waiting for data, but no more than 100ms */ int ret = ::poll(&fds[0], 1, 100); /* this would be bad... */ if (ret < 0) { log("poll error %d", errno); usleep(1000000); continue; } /* if we timed out waiting, we should send an update */ if (ret == 0) _send_needed = true; /* if we have new data from IO, go handle it */ if ((ret > 0) && (fds[0].revents & POLLIN)) io_recv(); /* send an update to IO if required */ if (_send_needed) { _send_needed = false; io_send(); } } if (_io_stream != nullptr) hx_stream_free(_io_stream); ::close(_fd); /* tell the dtor that we are exiting */ _task = -1; _exit(0); }