示例#1
0
            protected override WriteResult WriteSingleFragment(ByteBuffer buffer)
            {
                int err;
                int sent = SocketFunctions.manos_socket_send(Handle.ToInt32(), buffer.Bytes, buffer.Position,
                                                             buffer.Length, out err);

                if (sent < 0 && err != 0)
                {
                    RaiseError(Errors.SocketStreamFailure("Write failure", err));
                    return(WriteResult.Error);
                }
                else
                {
                    buffer.Skip(sent);
                    return(buffer.Length == 0 ? WriteResult.Consume : WriteResult.Continue);
                }
            }
示例#2
0
            protected override WriteResult WriteSingleFragment(UdpPacket packet)
            {
                int len, error;

                if (parent.IsConnected)
                {
                    len = SocketFunctions.manos_socket_send(Handle.ToInt32(), packet.Buffer.Bytes,
                                                            packet.Buffer.Position, packet.Buffer.Length, out error);
                }
                else
                {
                    ManosIPEndpoint ep = new IPEndPoint(IPAddress.Parse(packet.Address), packet.Port);
                    len = SocketFunctions.manos_socket_sendto_ip(Handle.ToInt32(), packet.Buffer.Bytes,
                                                                 packet.Buffer.Position, packet.Buffer.Length, ref ep, out error);
                }

                if (len < 0)
                {
                    RaiseError(Errors.SocketStreamFailure("Write failure", error));
                    return(WriteResult.Error);
                }
                return(WriteResult.Consume);
            }