5 // Martin Baulig <martin.baulig@xamarin.com>
7 // Copyright (c) 2015 Xamarin Inc. (http://www.xamarin.com)
9 // Permission is hereby granted, free of charge, to any person obtaining a copy
10 // of this software and associated documentation files (the "Software"), to deal
11 // in the Software without restriction, including without limitation the rights
12 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 // copies of the Software, and to permit persons to whom the Software is
14 // furnished to do so, subject to the following conditions:
16 // The above copyright notice and this permission notice shall be included in
17 // all copies or substantial portions of the Software.
19 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 namespace System.Net.Sockets
34 internal const int DefaultCloseTimeout = -1;
35 // don't change for default, otherwise breaking change
37 // this version does not throw.
38 internal void InternalShutdown (SocketShutdown how)
40 if (!is_connected || is_disposed)
43 Shutdown_internal (safe_handle, how, out error);
46 internal IAsyncResult UnsafeBeginConnect (EndPoint remoteEP, AsyncCallback callback, object state)
48 return BeginConnect (remoteEP, callback, state);
51 internal IAsyncResult UnsafeBeginSend (byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state)
53 return BeginSend (buffer, offset, size, socketFlags, callback, state);
56 internal IAsyncResult UnsafeBeginReceive (byte[] buffer, int offset, int size, SocketFlags socketFlags, AsyncCallback callback, object state)
58 return BeginReceive (buffer, offset, size, socketFlags, callback, state);
61 internal IAsyncResult BeginMultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
63 var segments = new ArraySegment<byte> [buffers.Length];
64 for (int i = 0; i < buffers.Length; i++)
65 segments [i] = new ArraySegment<byte> (buffers [i].Buffer, buffers [i].Offset, buffers [i].Size);
66 return BeginSend (segments, socketFlags, callback, state);
69 internal IAsyncResult UnsafeBeginMultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
71 return BeginMultipleSend (buffers, socketFlags, callback, state);
74 internal int EndMultipleSend (IAsyncResult asyncResult)
76 return EndSend (asyncResult);
79 internal void MultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags)
81 var segments = new ArraySegment<byte> [buffers.Length];
82 for (int i = 0; i < buffers.Length; i++)
83 segments [i] = new ArraySegment<byte> (buffers [i].Buffer, buffers [i].Offset, buffers [i].Size);
84 Send (segments, socketFlags);
87 internal void SetSocketOption (SocketOptionLevel optionLevel, SocketOptionName optionName, int optionValue, bool silent)
89 if (is_disposed && is_closed) {
92 throw new ObjectDisposedException (GetType ().ToString ());
97 SetSocketOption_internal (safe_handle, optionLevel, optionName, null,
98 null, optionValue, out error);
100 if (!silent && error != 0)
101 throw new SocketException (error);