public void Listen(int backlog) { int r = listen(Handle, backlog); if (r < 0) { throw UnixError.GetLastUnixException(); } }
//assigns a name to the socket public void Bind(byte[] localEnd) { int r = bind(Handle, localEnd, (uint)localEnd.Length); if (r < 0) { throw UnixError.GetLastUnixException(); } }
public UnixSocket() { //TODO: don't hard-code PF_UNIX and SOCK_STREAM or SocketType.Stream //AddressFamily family, SocketType type, ProtocolType proto int r = socket(AF_UNIX, SOCK_STREAM, 0); if (r < 0) { throw UnixError.GetLastUnixException(); } Handle = r; _ownsHandle = true; }
public int Write(byte *bufP, int count) { int r = 0; do { r = (int)write(Handle, bufP, (SizeT)count); }while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } return(r); }
//TODO: consider memory management public void Connect(byte[] remote_end) { int r = 0; do { r = connect(Handle, remote_end, (uint)remote_end.Length); } while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } Connected = true; }
public void Connect() { int r = 0; do { r = connect(Handle, null, 0); } while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } Connected = true; }
//TODO: consider memory management public void Close() { int r = 0; do { r = close(Handle); } while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } Handle = -1; Connected = false; }
public UnixSocket Accept() { byte[] addr = new byte[110]; uint addrlen = (uint)addr.Length; fixed(byte *addrP = addr) { int r = 0; do { r = accept(Handle, addrP, ref addrlen); } while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } return(new UnixSocket(r, true)); } }
public int Read(byte *bufP, int count) { int r = 0; do { r = (int)read(Handle, bufP, (SizeT)count); }while (r < 0 && UnixError.ShouldRetry); /* Read was successful */ if (r >= 0) { return(r); } var error = Marshal.GetLastWin32Error(); if (error == 11) /* EAGAIN (ignore for blocking sockets) */ { return(-error); } else if (error >= 103 && error <= 113) /* Bundle common socket errno identifiers */ { /* ECONNABORTED, ECONNRESET, ENOBUFS, ETIMEDOUT, ... */ // Console.WriteLine ("IO-Error " + error); throw new UnixSocketException(error); } else if (error == 9) /* EBADF */ { // Console.WriteLine ("Socket closed: bad file descriptor"); throw new UnixSocketException(error); } else { // Console.WriteLine ("Error " + error); throw UnixError.GetLastUnixException(); } }
public UnixException(int errno) : base($"Error {errno}: {UnixError.GetErrorString(errno)}") { Errno = errno; }