Lets consider following piece of code
pollfd file_descriptors[1];
file_descriptors[0].fd = sock_fd;
file_descriptors[0].events = POLLIN | POLLPRI;
int return_value = poll(file_descriptors, 1, 0);
if (return_value == -1) { cerr << strerror(errno); }
else if (return_value == 0) { cerr << "No data available to be read"; }
else {
int received = 0;
if (file_descriptors[0].revents & POLLIN) {
received += recv(sock_fd, buff, 1024, 0);
}
if (file_descriptors[0].revents & POLLPRI) {
recv(sock_fd, buff + received, 1024 - received, MSG_OOB);
}
}
Now I have three questions regarding the above code.
- If the call to poll() returns neither
-1
nor0
and sets thePOLLIN
flag in the bitmap revents for the first entry in thefile_descriptors
array, then will the call torecv()
block? If no, then will the data be read in instantaneously? - Assuming the call to
poll()
goes the same way as mentioned above. How much data is going to be read in? Is it just going to be the same as a regular call torecv()
? i.e. an arbitrary (to the programmer) amount less than or equal to1024
in the above case. Then if I want topoll()
before reading again, do I just repeat from the first invocation ofpoll()
? - What exactly is out-of-band data? I apologize for asking this here but I did look this up a little on Google and I didn't understand when exactly I can expect there to be out of band data in the socket to be read. Is the above way of reading in out-of-band data along with regular data correct?
Thank you!
Aucun commentaire:
Enregistrer un commentaire