+2003-02-16 Gonzalo Paniagua Javier <gonzalo@ximian.com>
+
+ * Socket.cs: make Worker.Connect and Receive work with non-blocking
+ sockets. May be Receive* and Send* in Worker need to do the same. I'll
+ wait for bug reports. Set IsCompleted to true before invoking the end
+ callback. Fixes bug #38136.
+
2003-01-23 Gonzalo Paniagua Javier <gonzalo@ximian.com>
* NetworkStream.cs: the check for disposed should not be done in the
private void End() {
((ManualResetEvent)result.AsyncWaitHandle).Set();
- callback(result);
result.IsCompleted=true;
+ callback(result);
}
public void Accept() {
public void Connect() {
lock(result) {
- socket.Connect(endpoint);
- End();
+ if (socket.Blocking) {
+ socket.Connect(endpoint);
+ End ();
+ return;
+ }
+
+ SocketException rethrow = null;
+ try {
+ socket.Connect (endpoint);
+ } catch (SocketException e) {
+ //WSAEINPROGRESS
+ if (e.NativeErrorCode != 10036)
+ throw;
+
+ socket.Poll (-1, SelectMode.SelectWrite);
+ try {
+ socket.Connect (endpoint);
+ } catch (SocketException e2) {
+ rethrow = e2;
+ }
+ }
+ End ();
+ if (rethrow != null)
+ throw rethrow;
}
}
public void Receive() {
lock(result) {
- total=socket.Receive(buffer, offset,
- size, sockflags);
- End();
+ if (socket.Blocking) {
+ total=socket.Receive(buffer, offset,
+ size, sockflags);
+ End();
+ return;
+ }
+
+ SocketException rethrow = null;
+ try {
+ total = socket.Receive (buffer, offset, size, sockflags);
+ } catch (SocketException e) {
+ //WSAEWOULDBLOCK
+ if (e.NativeErrorCode != 10035)
+ throw;
+
+ socket.Poll (-1, SelectMode.SelectRead);
+ try {
+ total = socket.Receive (buffer, offset, size, sockflags);
+ } catch (SocketException e2) {
+ rethrow = e2;
+ }
+ }
+ End ();
+ if (rethrow != null)
+ throw rethrow;
}
}