Example #1
0
        //way too many copies.  But for now we'll live with it.
        private StatusCode AskDnsServer(IPv4 dnsServer,
                                        byte[]    outData,
                                        out byte[] rcvData)
        {
            UDP udp = new UDP();

            udp.Bind(IPv4.Any, 0);
            udp.Connect(dnsServer, Dns.Format.ServerPort);

            Bytes packet = Bitter.FromByteArray(outData);

            udp.WriteData(packet);

            Bytes buffer;

            buffer = udp.PollReadData(TimeSpan.FromTicks(timeout.Ticks));

            //This is silly..I'll come back and clean this up.
            udp.Close();

            if (buffer == null)
            {
                rcvData = null;
                return(StatusCode.Timeout);
            }
            rcvData = new byte[buffer.Length];
            Bitter.ToByteArray(buffer, 0, buffer.Length, rcvData, 0);
            //delete buffer;

            return(StatusCode.Success);
        }
Example #2
0
        internal override int Send(byte[]     buffer,
                                   int offset,
                                   int size,
                                   SocketFlags socketFlags)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }

            if (size < 0 || size > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException("size");
            }

            // Copy the data into the shared heap
            Bytes dataToWrite = Bitter.FromByteArray(buffer, offset, size);

            return(Send(dataToWrite, socketFlags));
        }
Example #3
0
        internal override int Send(byte[]    buffer,
                                   int offset,
                                   int size,
                                   SocketFlags socketFlags)
        {
            ValidateBufferOffsets(buffer, offset, size);
            Bytes dataToWrite = Bitter.FromByteArray(buffer, offset, size);

            return(Send(dataToWrite, socketFlags));
        }
Example #4
0
 public void Set(byte[] buffer, int bufferStart, int bufferBytes)
 {
     {
         if (this.data == null || this.data.Length < bufferBytes)
         {
             this.data = new Bytes(new byte[bufferBytes]);
         }
         this.start  = 0;
         this.length = bufferBytes;
         Bitter.FromByteArray(this.data, 0, bufferBytes,
                              buffer, bufferStart);
     }
 }
Example #5
0
        internal override int SendTo(byte[]     buffer,
                                     int offset,
                                     int size,
                                     SocketFlags socketFlags,
                                     EndPoint remoteEP)
        {
            ValidateBufferOffsets(buffer, offset, size);

            if (socketFlags != SocketFlags.None)
            {
                // Invalid flags for this operation
                throw new SocketException(SocketErrors.WSAEINVAL);
            }

            IPEndPoint ep = remoteEP as IPEndPoint;

            if (ep == null)
            {
                throw new SocketException(SocketErrors.WSAEINVAL);
            }

            UdpConnectionContract /*.Imp*/ conn = (UdpConnectionContract)m_Conn.Acquire();

            try {
                if (conn.InState(UdpConnectionContract.State.Closed /*.Value*/))
                {
                    throw new SocketException(BAD_SOCKET_STATE_ERR);
                }

                // Copy the data to write into an ExHeap vector and send it
                Bytes dataToWrite = Bitter.FromByteArray(buffer, offset, size);

                conn.WriteTo((uint)ep.Address.m_addr,
                             unchecked ((ushort)ep.Port),
                             dataToWrite);
                // no longer own dataToWrite!

                return(size);
            }
            finally {
                m_Conn.Release(conn);
            }
        }