for c in clients do fs.readset.set(c)
if fs.select(max, 4, 0) == 0 then
- print "Error occured in select {socket.errno.to_s}"
+ print "Error occured in select {sys.errno.strerror}"
break
end
return new Socket.primitive_init(socket.accept)
end
- fun errno: Int do return socket.errno
end
class SocketSet
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/poll.h>
- #include <errno.h>
typedef int S_DESCRIPTOR;
typedef struct sockaddr_in S_ADDR_IN;
fun destroy `{ free(recv); `}
fun close: Int `{ return close( *recv ); `}
fun descriptor: Int `{ return *recv; `}
- fun errno: Int `{ return errno; `}
fun gethostbyname(n: String): FFSocketHostent import String.to_cstring `{ return gethostbyname(String_to_cstring(n)); `}
fun connect(addrIn: FFSocketAddrIn): Int `{ return connect( *recv, (S_ADDR*)addrIn, sizeof(*addrIn) ); `}
import end # Mark this module is a top level one. (must be only one)
+`{
+#include <errno.h>
+`}
+
###############################################################################
# System Classes #
###############################################################################
class Sys
# Instructions outside classes implicitly redefine this method.
fun main do end
+
+ # Number of the last error
+ fun errno: Int is extern `{
+ return errno;
+ `}
end
###############################################################################
`{
#include <stdio.h>
+#include <string.h>
`}
###############################################################################
end
redef class Int
+
+ # Wrapper of strerror C function
+ private fun strerror_ext: NativeString is extern `{
+ return strerror(recv);
+ `}
+
+ # Returns a string describing error number
+ fun strerror: String do return strerror_ext.to_s
+
# Fill `s` with the digits in base `base` of `self` (and with the '-' sign if 'signed' and negative).
# assume < to_c max const of char
fun fill_buffer(s: Buffer, base: Int, signed: Bool)
return v.int_instance(res)
else if pname == "native_int_to_s" then
return v.native_string_instance(recvval.to_s)
+ else if pname == "strerror_ext" then
+ return v.native_string_instance(recvval.strerror)
end
else if cname == "NativeFile" then
var recvval = args.first.val
return v.int_instance(parser_action(args[1].to_i, args[2].to_i))
else if pname == "file_getcwd" then
return v.native_string_instance(getcwd)
+ else if pname == "errno" then
+ return v.int_instance(sys.errno)
end
fatal(v, "NOT YET IMPLEMENTED extern {mpropdef}")
abort