e.curSocket = this;
Worker w = e.Worker;
w.Init (this, e, SocketOperation.Accept);
- socket_pool_queue (Worker.Dispatcher, w.result);
+ int count;
+ lock (readQ) {
+ readQ.Enqueue (e.Worker);
+ count = readQ.Count;
+ }
+ if (count == 1)
+ socket_pool_queue (Worker.Dispatcher, w.result);
return true;
}
#endif
throw new InvalidOperationException ();
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Accept);
- socket_pool_queue (Worker.Dispatcher, req);
+ int count;
+ lock (readQ) {
+ readQ.Enqueue (req.Worker);
+ count = readQ.Count;
+ }
+ if (count == 1)
+ socket_pool_queue (Worker.Dispatcher, req);
return req;
}
req.Offset = 0;
req.Size = receiveSize;
req.SockFlags = SocketFlags.None;
- socket_pool_queue (Worker.Dispatcher, req);
+ int count;
+ lock (readQ) {
+ readQ.Enqueue (req.Worker);
+ count = readQ.Count;
+ }
+ if (count == 1)
+ socket_pool_queue (Worker.Dispatcher, req);
return req;
}
req.Size = receiveSize;
req.SockFlags = SocketFlags.None;
req.AcceptSocket = acceptSocket;
- socket_pool_queue (Worker.Dispatcher, req);
+ int count;
+ lock (readQ) {
+ readQ.Enqueue (req.Worker);
+ count = readQ.Count;
+ }
+ if (count == 1)
+ socket_pool_queue (Worker.Dispatcher, req);
return(req);
}
socket_pool_queue (Worker.Dispatcher, req);
return(req);
}
+
+ void CheckRange(byte[] buffer, int offset, int size)
+ {
+ if (offset < 0 || offset > buffer.Length)
+ throw new ArgumentOutOfRangeException ("offset");
+
+ if (size < 0 || size > buffer.Length - offset)
+ throw new ArgumentOutOfRangeException ("size");
+ }
public IAsyncResult BeginReceive(byte[] buffer, int offset,
int size,
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange(buffer, offset, size);
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.Receive);
req.Buffer = buffer;
if (remote_end == null)
throw new ArgumentNullException ("remote_end");
- if (offset < 0)
- throw new ArgumentOutOfRangeException ("offset", "offset must be >= 0");
-
- if (size < 0)
- throw new ArgumentOutOfRangeException ("size", "size must be >= 0");
-
- if (offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset, size", "offset + size exceeds the buffer length");
+ CheckRange (buffer, offset, size);
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.ReceiveFrom);
req.Buffer = buffer;
if (remoteEP == null)
throw new ArgumentNullException ("remoteEP");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (bufer, offset, size);
throw new NotImplementedException ();
}
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0)
- throw new ArgumentOutOfRangeException ("offset", "offset must be >= 0");
-
- if (size < 0)
- throw new ArgumentOutOfRangeException ("size", "size must be >= 0");
-
- if (offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset, size", "offset + size exceeds the buffer length");
+ CheckRange (buffer, offset, size);
if (!connected)
throw new SocketException ((int)SocketError.NotConnected);
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0)
- throw new ArgumentOutOfRangeException ("offset", "offset must be >= 0");
-
- if (size < 0)
- throw new ArgumentOutOfRangeException ("size", "size must be >= 0");
-
- if (offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset, size", "offset + size exceeds the buffer length");
+ CheckRange (buffer, offset, size);
SocketAsyncResult req = new SocketAsyncResult (this, state, callback, SocketOperation.SendTo);
req.Buffer = buffer;
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (size < 0 || size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, 0, size);
SocketError error;
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, offset, size);
SocketError error;
if (buffer == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, offset, size);
return Receive_nochecks (buffer, offset, size, flags, out error);
}
if (remoteEP == null)
throw new ArgumentNullException ("remoteEP");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, offset, size);
return ReceiveFrom_nochecks (buffer, offset, size, flags, ref remoteEP);
}
if (remoteEP == null)
throw new ArgumentNullException ("remoteEP");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, offset, size);
/* FIXME: figure out how we get hold of the
* IPPacketInformation
if (buf == null)
throw new ArgumentNullException ("buf");
- if (size < 0 || size > buf.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buf, 0, size);
SocketError error;
if (buf == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0 || offset > buf.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buf.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buf, offset, size);
SocketError error;
if (buf == null)
throw new ArgumentNullException ("buffer");
- if (offset < 0 || offset > buf.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buf.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buf, offset, size);
return Send_nochecks (buf, offset, size, flags, out error);
}
if (remote_end == null)
throw new ArgumentNullException ("remote_end");
- if (size < 0 || size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, 0, size);
return SendTo_nochecks (buffer, 0, size, flags, remote_end);
}
if (remote_end == null)
throw new ArgumentNullException("remote_end");
- if (offset < 0 || offset > buffer.Length)
- throw new ArgumentOutOfRangeException ("offset");
-
- if (size < 0 || offset + size > buffer.Length)
- throw new ArgumentOutOfRangeException ("size");
+ CheckRange (buffer, offset, size);
return SendTo_nochecks (buffer, offset, size, flags, remote_end);
}