// Get the address family for a socket file descriptor. // Returns a negative errno code if not a socket. public static int __syscall_socket_family(int fd) { Stream stream = FileTable.GetStream(fd); if (stream == null) { return(-9); /* EBADF */ } SocketStream sstream = (stream as SocketStream); if (sstream == null) { return(-88); /* ENOTSOCK */ } AddressFamily family = sstream.Socket.AddressFamily; if (family == AddressFamily.InterNetwork) { return(2); /* AF_INET */ } else if (family == AddressFamily.InterNetworkV6) { return(10); /* AF_INET6 */ } else { return(-22); /* EINVAL */ } }
// Set the connected state on a socket. public static void __syscall_set_connected(int fd, int value) { Stream stream = FileTable.GetStream(fd); if (stream is SocketStream) { ((SocketStream)stream).Connected = (value != 0); } }
// Set the listening state on a socket. public static void __syscall_set_listening(int fd, int value) { Stream stream = FileTable.GetStream(fd); if (stream is SocketStream) { ((SocketStream)stream).Listening = (value != 0); } }
// Determine if a socket has been marked as connected. public static int __syscall_is_connected(int fd) { Stream stream = FileTable.GetStream(fd); if (stream is SocketStream) { return(((SocketStream)stream).Connected ? 1 : 0); } else { return(0); } }
// Determine if a socket has been marked for listening. public static int __syscall_is_listening(int fd) { Stream stream = FileTable.GetStream(fd); if (stream is SocketStream) { return(((SocketStream)stream).Listening ? 1 : 0); } else { return(0); } }
// Determine if a file descriptor is non-blocking. public static int __syscall_is_nonblocking(int fd) { Stream stream = FileTable.GetStream(fd); if (stream is IFDOperations) { return(((IFDOperations)stream).NonBlocking ? 1 : 0); } else { return(0); } }
// Set the non-blocking state for a file descriptor. public static void __syscall_set_nonblocking(int fd, int value) { Stream stream = FileTable.GetStream(fd); if (stream is IFDOperations) { ((IFDOperations)stream).NonBlocking = (value != 0 ? true : false); } else { throw new NotSupportedException(); } }
// Get a native operating system file descriptor. public static int __syscall_native_fd(int fd) { Stream stream = FileTable.GetStream(fd); if (stream is IFDOperations) { return(((IFDOperations)stream).NativeFd); } else if (stream is FileStream) { return((int)(((FileStream)stream).Handle)); } else { return(-1); } }
// Get a "select" operating system file descriptor. public static int __syscall_select_fd(int fd) { Stream stream = FileTable.GetStream(fd); if (stream is IFDOperations) { return(((IFDOperations)stream).SelectFd); } else if (stream is FileStream && Environment.OSVersion.Platform == (PlatformID)128) { // We only allow FileStream selects on Unix systems. return((int)(((FileStream)stream).Handle)); } else { return(-1); } }
// Get the socket object for a file descriptor. Returns null // if an error occurred (which is written to "errno"). public unsafe static Socket __syscall_get_socket(int fd, int *errno) { Stream stream = FileTable.GetStream(fd); if (stream == null) { *errno = 9; /* EBADF */ return(null); } SocketStream sstream = (stream as SocketStream); if (sstream != null) { return(sstream.Socket); } else { *errno = 88; /* ENOTSOCK */ return(null); } }