16 portfd
= port_create();
26 sockwant(Socket
*s
, int rw
)
43 if (!s
->added
&& !rw
) {
45 } else if (!s
->added
&& rw
) {
47 return port_associate(portfd
, PORT_SOURCE_FD
, s
->fd
, events
, (void *)s
);
49 return port_dissociate(portfd
, PORT_SOURCE_FD
, s
->fd
);
51 port_dissociate(portfd
, PORT_SOURCE_FD
, s
->fd
);
52 return port_associate(portfd
, PORT_SOURCE_FD
, s
->fd
, events
, (void *)s
);
58 socknext(Socket
**s
, int64 timeout
)
65 ts
.tv_sec
= timeout
/ 1000000000;
66 ts
.tv_nsec
= timeout
% 1000000000;
67 r
= port_getn(portfd
, &pe
, 1, &n
, &ts
);
68 if (r
== -1 && errno
!= ETIME
&& errno
!= EINTR
) {
75 if (pe
.portev_events
& POLLHUP
) {
77 } else if (pe
.portev_events
& POLLIN
) {
78 if (sockwant(*s
, 'r') == -1) {
82 } else if (pe
.portev_events
& POLLOUT
) {
83 if (sockwant(*s
, 'w') == -1) {