Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int pr_netio_read(pr_netio_stream_t *nstrm, char *buf, size_t buflen,
- int bufmin) {
- int bread = 0, total = 0;
- /* Sanity check. */
- if (!nstrm) {
- errno = EINVAL;
- return -1;
- }
- if (nstrm->strm_fd == -1) {
- errno = (nstrm->strm_errno ? nstrm->strm_errno : EBADF);
- return -1;
- }
- if (bufmin < 1)
- bufmin = 1;
- if (bufmin > buflen)
- bufmin = buflen;
- while (bufmin > 0) {
- polling:
- switch (pr_netio_poll(nstrm)) {
- case 1:
- return -2;
- case -1:
- return -1;
- default:
- do {
- pr_signals_handle();
- run_schedule();
- switch (nstrm->strm_type) {
- case PR_NETIO_STRM_CTRL:
- bread = ctrl_netio ? ctrl_netio->read(nstrm, buf, buflen) :
- core_ctrl_netio->read(nstrm, buf, buflen);
- break;
- case PR_NETIO_STRM_DATA:
- bread = data_netio ? data_netio->read(nstrm, buf, buflen) :
- core_data_netio->read(nstrm, buf, buflen);
- break;
- case PR_NETIO_STRM_OTHR:
- bread = othr_netio ? othr_netio->read(nstrm, buf, buflen) :
- core_othr_netio->read(nstrm, buf, buflen);
- break;
- }
- #ifdef EAGAIN
- if (bread == -1 && errno == EAGAIN)
- goto polling;
- #endif
- } while (bread == -1 && errno == EINTR);
- break;
- }
- if (bread == -1) {
- nstrm->strm_errno = errno;
- return -1;
- }
- /* EOF? */
- if (bread == 0) {
- nstrm->strm_errno = 0;
- break;
- }
- buf += bread;
- total += bread;
- bufmin -= bread;
- buflen -= bread;
- }
- return total;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement