unsafe public int Read(byte *bufP, int count) { int r = 0; var fdarray = new PollFD[1]; fdarray[0].fd = Handle; fdarray[0].events = PollEvents.POLLIN | PollEvents.EPOLLRDHUP | PollEvents.EPOLLHUP | PollEvents.EPOLLERR; do { if (poll(fdarray, 1, -1) == -1) { break; } if ((fdarray[0].revents & PollEvents.POLLIN) == 0) { break; } r = (int)read(Handle, bufP, (SizeT)count); } while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } return(r); }
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[] local_end) { int r = bind(Handle, local_end, (uint)local_end.Length); if (r < 0) { throw UnixError.GetLastUnixException(); } }
public int WriteV(IOVector *iov, int count) { //FIXME: Handle EINTR here or elsewhere //FIXME: handle r != count //TODO: check offset correctness int r = (int)writev(Handle, iov, count); if (r < 0) { throw UnixError.GetLastUnixException(); } return(r); }
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 SendMsg(void *bufP, int flags) { int r = 0; do { r = (int)sendmsg(Handle, bufP, flags); } while (r < 0 && UnixError.ShouldRetry); if (r < 0) { throw UnixError.GetLastUnixException(); } return(r); }
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 Shutdown() { int r = 0; if (Handle == -1 && connected == false) { return; } r = shutdown(Handle, ShutdownOptions.SHUT_RDWR); if (r < 0) { throw UnixError.GetLastUnixException(); } }
public int Write(IOVector[] iov, int offset, int count) { //FIXME: Handle EINTR here or elsewhere //FIXME: handle r != count //TODO: check offset correctness fixed(IOVector *bufP = &iov[offset]) { int r = (int)writev(Handle, bufP + offset, count); if (r < 0) { throw UnixError.GetLastUnixException(); } return(r); } }
//TODO: consider memory management public void Close() { int r = 0; if (Handle == -1 && connected == false) { return; } 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(); } //TODO: use the returned addr //string str = Encoding.Default.GetString (addr, 0, (int)addrlen); return(new UnixSocket(r, true)); } }