I'm using WSAPoll for my project. I used tracking POLLIN and POLLOUT events. Everything worked nice. When I add POLLHUP as event, WSAPoll returns error 10022 (Invalid argument).
I've no idea what's wrong, please guide me how to fix it:(
cc_qnt
- quantity of connected clients
int ev_cnt = WSAPoll(pfd, cc_qnt + 1, 100);
if (ev_cnt > 0) {
for (i = 0; i < cc_qnt; i++) {
if (pfd[i].revents & POLLHUP) {
// some code
}
if (pfd[i].revents & POLLIN) {
// some code
}
}
if (pfd[cc_qnt].revents & POLLIN) {
In this part we have new connection ready for accepting. We edit pfd[cc_qnt]
adding new socket (returned by accept) instead of listening socket. Then we reallocate pfd with size + 1, copying previous data and adding listening socket at the end of cc array.
int addrlen = sizeof(addr);
cc[cc_qnt].s = accept(ls, (struct sockaddr*) &addr, &addrlen);
cc[cc_qnt].ip = ntohl(addr.sin_addr.s_addr);
cc[cc_qnt].sent_put = 0;
cc[cc_qnt].c_cl_cn = 0;
pfd[cc_qnt].fd = cc[i].s;
pfd[cc_qnt].events = POLLIN | POLLOUT | POLLHUP;
cc_qnt++;
pfd = init_pfd(pfd, ls, cc_qnt);
}
}
else if (ev_cnt < 0) {
exit(printf("\nprocess_events: WSAPoll, ev_cnt = %d, WSAGetLastError: %d \n", ev_cnt, WSAGetLastError()));
}
Everything I changed for tracking POLLHUP - adding it's bit to pfd[cc_qnt].events and WSAPoll started returning error. I expect tracking POLLHUP event.