Re: Create new socket
- Posted by euphoric (admin) Aug 25, 2009
- 933 views
jeremy said...
socket s = create() if atom(s) then printf(1, "Could not create socket, error number: %d\n", { s }) end if
Or:
socket s = create() if not valid(s) then -- a sockets.e function to validate your socket* printf(1, "Error %d:%s", { get_error_num( s ), get_error_msg( s ) }) -- sockets.e error management -- or printf(1, "Error %d:%s", get_error(s) ) -- or get_error() could return {errnum,errmsg} -- or printf(1, "Error %d:%s", s[2] ) -- on fail, s is {0,{errnum,errmsg}} else -- process normally end if
-- in sockets.e public function valid(object s) return sequence(s) and length(s) > 0 and s[1] -- hopefully this short-circuits... end function