public SOCKADDR_STORAGE get_sockaddr_storage(socklen_t *len = NULL) { SOCKADDR_STORAGE sa; const byte family = get_family(); if (family == AF_INET) { sockaddr_in *sin = (sockaddr_in *)&sa; if (len) { *len = sizeof(sockaddr_in); } memset(sin, 0, sizeof(sockaddr_in)); sin.sin_family = family; sin.sin_port = htons(_port); sin.sin_addr.s_addr = _sin4; } else { sockaddr_in6 *sin6 = (sockaddr_in6 *)&sa; memset(sin6, 0, sizeof(sockaddr_in6)); if (len) { *len = sizeof(sockaddr_in6); } sin6.sin6_family = family; sin6.sin6_addr = _in._in6addr; sin6.sin6_port = htons(_port); } return(sa); }
/// <summary> /// Adds an accept to the Submission Queue without it being submitted. /// The actual submission can be deferred to avoid unnecessary memory barriers. /// </summary> /// <param name="fd">File descriptor to accept on</param> /// <param name="addr">(out) the address of the connected client.</param> /// <param name="addrLen">(out) the length of the address</param> /// <param name="flags">Flags as per accept4</param> /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param> /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param> /// <exception cref="SubmissionQueueFullException">If no more free space in the Submission Queue is available</exception> public void PrepareAccept(int fd, sockaddr *addr, socklen_t *addrLen, int flags, ulong userData = 0, SubmissionOption options = SubmissionOption.None) { if (!TryPrepareAccept(fd, addr, addrLen, flags, userData, options)) { ThrowSubmissionQueueFullException(); } }
public int sceNetInetRecvfrom(int SocketId, void *BufferPointer, int BufferLength, SocketFlags SocketFlags, sockaddr_in *From, socklen_t *FromLength) { var Socket = Sockets.Get(SocketId); EndPoint EndPoint = new IPEndPoint(From->sin_addr.Address, From->sin_port); return(Socket.ReceiveFrom(ArrayUtils.CreateArray <byte>(BufferPointer, BufferLength), SocketFlags, ref EndPoint)); }
public unsafe LinuxSocket Accept4(sockaddr *addr, socklen_t *addrLen, int flags) { int rv; int error = 0; do { rv = accept4(_fd, addr, addrLen, flags); } while (rv == -1 && Retry(error = errno)); if (rv == -1) { ThrowHelper.ThrowNewErrnoException(error); } return(rv);
/// <summary> /// Prepares this Submission Queue Entry as an accept. /// </summary> /// <param name="fd">File descriptor to accept from</param> /// <param name="addr">(out) the address of the connected client.</param> /// <param name="addrLen">(out) the length of the address</param> /// <param name="flags">Flags as per accept4</param> /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param> /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param> /// <param name="personality">The personality to impersonate for this submission</param> public void PrepareAccept(int fd, sockaddr *addr, socklen_t *addrLen, int flags, ulong userData = 0, SubmissionOption options = SubmissionOption.None, ushort personality = 0) { var sqe = _sqe; unchecked { sqe->opcode = IORING_OP_ACCEPT; sqe->flags = (byte)options; sqe->fd = fd; sqe->off = (ulong)addrLen; sqe->addr = (ulong)addr; sqe->accept_flags = (uint)flags; sqe->user_data = userData; sqe->personality = personality; } }
public AcceptSocketContext(LinuxSocket socket, IPEndPoint endPoint, ChannelWriter <ConnectionContext> acceptQueue) { EndPoint = endPoint; AcceptQueue = acceptQueue; Socket = socket; sockaddr_storage storage = default; var addrHandle = GCHandle.Alloc(storage, GCHandleType.Pinned); _addr = (sockaddr_storage *)addrHandle.AddrOfPinnedObject(); _addrHandle = addrHandle; socklen_t addrLen = SizeOf.sockaddr_storage; var addrLenHandle = GCHandle.Alloc(addrLen, GCHandleType.Pinned); _addLen = (socklen_t *)addrLenHandle.AddrOfPinnedObject(); _addrLenHandle = addrLenHandle; }
public static extern unsafe int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
public static extern unsafe int getsockname(int sockfd, sockaddr *addr, socklen_t *addrlen);
public static extern unsafe size_t recvfrom(int sockfd, void *buf, size_t len, int flags, sockaddr *dest_addr, socklen_t *addrlen);
public int sceNetInetAccept(int SocketId, sockaddr *Address, socklen_t *AddressLength) { throw new NotImplementedException(); }
public int sceNetInetGetsockopt(int s, int level, int optname, void *optval, socklen_t *optlen) { throw new NotImplementedException(); }
public static unsafe PosixResult GetSockOpt(SafeHandle socket, int level, int optname, void *optval, socklen_t *optlen) { int rv = getsockopt(socket.DangerousGetHandle().ToInt32(), level, optname, optval, optlen); return(PosixResult.FromReturnValue(rv)); }
public static extern unsafe int accept(int sockfd, byte *addr, socklen_t *addrlen);
/// <summary> /// Attempts to add an accept to the Submission Queue without it being submitted. /// The actual submission can be deferred to avoid unnecessary memory barriers. /// </summary> /// <param name="fd">File descriptor to accept on</param> /// <param name="addr">(out) the address of the connected client.</param> /// <param name="addrLen">(out) the length of the address</param> /// <param name="flags">Flags as per accept4</param> /// <param name="userData">User data that will be returned with the respective <see cref="Completion"/></param> /// <param name="options">Options for the handling of the prepared Submission Queue Entry</param> /// <returns><code>false</code> if the submission queue is full. <code>true</code> otherwise.</returns> public bool TryPrepareAccept(int fd, sockaddr *addr, socklen_t *addrLen, int flags, ulong userData = 0, SubmissionOption options = SubmissionOption.None) => TryPrepareReadWrite(IORING_OP_ACCEPT, fd, addr, 0, (long)addrLen, flags, userData, options);
public static extern unsafe int getpeername(int sockfd, byte *addr, socklen_t *addrlen);