Advertisement
Guest User

Untitled

a guest
Jun 27th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. int ioset_close(struct io_fd **fdp)
  2. {
  3.     return ioset_shutdown(fdp, IOFD_SHUTDOWN);
  4. }
  5.  
  6. int ioset_shutdown(struct io_fd **fdp, int mode)
  7. {
  8.     int res;
  9.     struct io_fd *fd = *fdp;
  10.     struct ioq *send = &fd->send;
  11.  
  12.     *fdp = NULL;
  13.     if (fd->close_cb)
  14.         fd->close_cb(fd);
  15.     if ((send->get != send->put) && (mode & IOFD_FLUSH)) {
  16.         res = fcntl(fd->fd, F_GETFL);
  17.         fcntl(fd->fd, F_SETFL, res&~O_NONBLOCK);
  18.         ioset_flush_sendq(fd);
  19.         if (send->get != send->put)
  20.             ioset_flush_sendq(fd);
  21.     }
  22.     res = fd->fd;
  23.     epoll_remove(fd);
  24.     free(fd->send.buf);
  25.     free(fd->recv.buf);
  26.     free(fd);
  27.     return (mode & IOFD_CLOSE) ? close(res) : res;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement