public static MonitorEvent Read([NotNull] SocketBase s) { var msg = new Msg(); msg.InitEmpty(); s.TryRecv(ref msg, SendReceiveConstants.InfiniteTimeout); int pos = msg.Offset; ByteArraySegment data = msg.Data; var @event = (SocketEvents)data.GetInteger(Endianness.Little, pos); pos += 4; var len = (int)data[pos++]; string addr = data.GetString(len, pos); pos += len; var flag = (int)data[pos++]; object arg = null; if (flag == ValueInteger) { arg = data.GetInteger(Endianness.Little, pos); } else if (flag == ValueChannel) { IntPtr value = s_sizeOfIntPtr == 4 ? new IntPtr(data.GetInteger(Endianness.Little, pos)) : new IntPtr(data.GetLong(Endianness.Little, pos)); GCHandle handle = GCHandle.FromIntPtr(value); AsyncSocket socket = null; if (handle.IsAllocated) { socket = handle.Target as AsyncSocket; } handle.Free(); arg = socket; } return(new MonitorEvent(@event, addr, arg)); }
private bool EightByteSizeReady() { m_tmpbuf.Reset(); // 8-byte payload length is read. Allocate the buffer // for message body and read the message data into it. long payloadLength = m_tmpbuf.GetLong(Endian, 0); // There has to be at least one byte (the flags) in the message). if (payloadLength == 0) { DecodingError(); return(false); } // Message size must not exceed the maximum allowed size. if (m_maxMessageSize >= 0 && payloadLength - 1 > m_maxMessageSize) { DecodingError(); return(false); } // Message size must fit within range of size_t data type. if (payloadLength - 1 > int.MaxValue) { DecodingError(); return(false); } int msgSize = (int)(payloadLength - 1); // in_progress is initialised at this point so in theory we should // close it before calling init_size, however, it's a 0-byte // message and thus we can treat it as uninitialised... m_inProgress.InitPool(msgSize); NextStep(m_tmpbuf, 1, FlagsReadyState); return(true); }
private bool EightByteSizeReady() { m_tmpbuf.Reset(); // The payload size is encoded as 64-bit unsigned integer. // The most significant byte comes first. long msg_size = m_tmpbuf.GetLong(Endian, 0); // Message size must not exceed the maximum allowed size. if (m_maxmsgsize >= 0) { if (msg_size > m_maxmsgsize) { DecodingError(); return(false); } } // Message size must fit within range of size_t data type. if (msg_size > int.MaxValue) { DecodingError(); return(false); } // in_progress is initialised at this point so in theory we should // close it before calling init_size, however, it's a 0-byte // message and thus we can treat it as uninitialised. m_inProgress = new Msg((int)msg_size); m_inProgress.SetFlags(m_msgFlags); NextStep(m_inProgress.Data, m_inProgress.Size, MessageReadyState); return(true); }