socket :: PollFD :: defaultinit
# Wrapper for the data structure used for polling on a socket
class PollFD
super FinalizableOnce
# The PollFD object
private var poll_struct: NativeSocketPollFD
# A collection of the events to be watched
var events: Array[NativeSocketPollValues]
# Create a PollFD object from NativePollFD informations
init from_poll_values(pid: Int, events: Array[NativeSocketPollValues])
do
assert events.length >= 1
var events_in_one = events[0]
for i in [1 .. events.length - 1] do
events_in_one += events[i]
end
var poll_struct = new NativeSocketPollFD(pid, events_in_one)
init(poll_struct, events)
end
# Reads the response and returns an array with the type of events that have been found
private fun check_response(response: Int): Array[NativeSocketPollValues]
do
var resp_array = new Array[NativeSocketPollValues]
for i in events do
if c_check_resp(response, i) != 0 then
resp_array.push(i)
end
end
return resp_array
end
# Checks if the poll call has returned true for a particular type of event
private fun c_check_resp(response: Int, mask: NativeSocketPollValues): Int
`{
return response & mask;
`}
redef fun finalize_once
do
poll_struct.free
end
end
lib/socket/socket_c.nit:38,1--86,3