nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: example: rosettacode 100 doors
[nit.git]
/
lib
/
socket
/
socket_c.nit
diff --git
a/lib/socket/socket_c.nit
b/lib/socket/socket_c.nit
index
793b1c5
..
44aff9e
100644
(file)
--- a/
lib/socket/socket_c.nit
+++ b/
lib/socket/socket_c.nit
@@
-37,6
+37,7
@@
in "C" `{
# Wrapper for the data structure PollFD used for polling on a socket
class PollFD
# Wrapper for the data structure PollFD used for polling on a socket
class PollFD
+ super FinalizableOnce
# The PollFD object
private var poll_struct: NativeSocketPollFD
# The PollFD object
private var poll_struct: NativeSocketPollFD
@@
-76,6
+77,10
@@
class PollFD
return response & mask;
`}
return response & mask;
`}
+ redef fun finalize_once
+ do
+ poll_struct.free
+ end
end
# Data structure used by the poll function
end
# Data structure used by the poll function
@@
-140,12
+145,14
@@
extern class NativeSocket `{ int* `}
`}
# Sets an option for the socket
`}
# Sets an option for the socket
- fun setsockopt(level: NativeSocketOptLevels, option_name: NativeSocketOptNames, option_value: Int) `{
+ #
+ # Returns `true` on success.
+ fun setsockopt(level: NativeSocketOptLevels, option_name: NativeSocketOptNames, option_value: Int): Bool `{
int err = setsockopt(*recv, level, option_name, &option_value, sizeof(int));
if(err != 0){
int err = setsockopt(*recv, level, option_name, &option_value, sizeof(int));
if(err != 0){
- perror("Error on setsockopts: ");
- exit(1);
+ return 0;
}
}
+ return 1;
`}
fun bind(addrIn: NativeSocketAddrIn): Int `{ return bind(*recv, (struct sockaddr*)addrIn, sizeof(*addrIn)); `}
`}
fun bind(addrIn: NativeSocketAddrIn): Int `{ return bind(*recv, (struct sockaddr*)addrIn, sizeof(*addrIn)); `}