本文整理汇总了C#中SocketFlags类的典型用法代码示例。如果您正苦于以下问题:C# SocketFlags类的具体用法?C# SocketFlags怎么用?C# SocketFlags使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketFlags类属于命名空间,在下文中一共展示了SocketFlags类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Receive
public static int Receive(this Socket socket, byte[] buffer, int offset, int size, int timeout, SocketFlags socketFlags)
{
if (!WaitForData(socket, timeout))
return 0;
return socket.Receive(buffer, offset, size, socketFlags);
}
开发者ID:luhcmps,项目名称:LSCoder.Net.Ftp,代码行数:7,代码来源:SocketExtension.cs
示例2: ReceiveAsync
public static Task<int> ReceiveAsync(
this Socket socket,
IList<ArraySegment<byte>> buffers,
SocketFlags socketFlags)
{
return Task<int>.Factory.FromAsync(socket.BeginReceive, socket.EndReceive, buffers, socketFlags, null);
}
开发者ID:JonHanna,项目名称:corefx,代码行数:7,代码来源:SocketTaskExtensions.cs
示例3: MultipleSend
internal void MultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags)
{
var segments = new ArraySegment<byte> [buffers.Length];
for (int i = 0; i < buffers.Length; i++)
segments [i] = new ArraySegment<byte> (buffers [i].Buffer, buffers [i].Offset, buffers [i].Size);
Send (segments, socketFlags);
}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:Socket.cs
示例4: Receive_internal
private static int Receive_internal (IntPtr sock,
WSABUF[] bufarray,
SocketFlags flags,
out int error)
{
throw new System.NotImplementedException();
}
开发者ID:desunit,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:Socket.Mosa.cs
示例5: ToFrameClientObservable
public static IObservable<DisposableByteBuffer> ToFrameClientObservable(this Socket socket, SocketFlags socketFlags, BufferManager bufferManager)
{
return Observable.Create<DisposableByteBuffer>(async (observer, token) =>
{
var headerBuffer = new byte[sizeof(int)];
try
{
while (!token.IsCancellationRequested)
{
if (await socket.ReceiveCompletelyAsync(headerBuffer, headerBuffer.Length, socketFlags, token) != headerBuffer.Length)
break;
var length = BitConverter.ToInt32(headerBuffer, 0);
var buffer = bufferManager.TakeBuffer(length);
if (await socket.ReceiveCompletelyAsync(buffer, length, socketFlags, token) != length)
break;
observer.OnNext(new DisposableByteBuffer(buffer, length, Disposable.Create(() => bufferManager.ReturnBuffer(buffer))));
}
observer.OnCompleted();
socket.Close();
}
catch (Exception error)
{
observer.OnError(error);
}
});
}
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:31,代码来源:FrameClientExtensions.cs
示例6: ReceiveAsync
/// <summary>
/// Asynchronously receives data from a connected socket.
/// </summary>
/// <param name="socket">
/// The socket from which to read data.
/// </param>
/// <param name="buffer">
/// An array of type <see cref="byte"/> that is the storage location for
/// the received data.
/// </param>
/// <param name="offset">
/// The zero-based position in the <paramref name="buffer"/> parameter at which to
/// start storing data.
/// </param>
/// <param name="size">
/// The number of bytes to receive.
/// </param>
/// <param name="socketFlags">
/// A bitwise combination of the <see cref="SocketFlags"/> values.
/// </param>
/// <returns>
/// The number of bytes received.
/// </returns>
public static Task<int> ReceiveAsync(
this Socket socket,
byte[] buffer,
int offset,
int size,
SocketFlags socketFlags)
{
var tcs = new TaskCompletionSource<int>(socket);
socket.BeginReceive(
buffer,
offset,
size,
socketFlags,
iar =>
{
var t = (TaskCompletionSource<int>)iar.AsyncState;
var s = (Socket)t.Task.AsyncState;
try
{
t.TrySetResult(s.EndReceive(iar));
}
catch (Exception ex)
{
t.TrySetException(ex);
}
},
tcs);
return tcs.Task;
}
开发者ID:vebin,项目名称:madb,代码行数:54,代码来源:SocketExtensions.cs
示例7: ToClientObservable
public static IObservable<ByteBuffer> ToClientObservable(this Socket socket, int size, SocketFlags socketFlags)
{
return Observable.Create<ByteBuffer>(async (observer, token) =>
{
var buffer = new byte[size];
try
{
while (!token.IsCancellationRequested)
{
var received = await socket.ReceiveAsync(buffer, 0, size, socketFlags);
if (received == 0)
break;
observer.OnNext(new ByteBuffer(buffer, received));
}
observer.OnCompleted();
}
catch (Exception error)
{
observer.OnError(error);
}
});
}
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:25,代码来源:ClientExtensions.cs
示例8: Init
public void Init (Socket socket, AsyncCallback callback, object state, SocketOperation operation)
{
base.Init (callback, state);
this.socket = socket;
this.handle = socket != null ? socket.Handle : IntPtr.Zero;
this.operation = operation;
DelayedException = null;
EndPoint = null;
Buffer = null;
Offset = 0;
Size = 0;
SockFlags = SocketFlags.None;
AcceptSocket = null;
Addresses = null;
Port = 0;
Buffers = null;
ReuseSocket = false;
CurrentAddress = 0;
AcceptedSocket = null;
Total = 0;
error = 0;
EndCalled = 0;
}
开发者ID:nickolyamba,项目名称:mono,代码行数:29,代码来源:SocketAsyncResult.cs
示例9: BeginMultipleSend
internal IAsyncResult BeginMultipleSend (BufferOffsetSize[] buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
{
var segments = new ArraySegment<byte> [buffers.Length];
for (int i = 0; i < buffers.Length; i++)
segments [i] = new ArraySegment<byte> (buffers [i].Buffer, buffers [i].Offset, buffers [i].Size);
return BeginSend (segments, socketFlags, callback, state);
}
开发者ID:Profit0004,项目名称:mono,代码行数:7,代码来源:Socket.cs
示例10: BeginReceive
public IAsyncResult BeginReceive(IList<ArraySegment<byte>> buffers, SocketFlags socketFlags, AsyncCallback callback, object state)
{
Encoding.UTF8.GetBytes(_request).CopyTo(buffers[0].Array, 0);
var result = new Mock<IAsyncResult>();
result.Setup(r => r.AsyncState).Returns(state);
callback(result.Object);
return result.Object;
}
开发者ID:emiaj,项目名称:Fleck,代码行数:8,代码来源:HandshakeHandlerTests.cs
示例11: CrosReceive
/// <summary>
/// Receives data from connected <see cref="CrosSocket"/> and stores it into the buffer using specified <see cref="SocketFlags"/>, buffer is resized to data received
/// </summary>
/// <param name="buffer">Array which will contain received data</param>
/// <param name="socketFlags">SocketFlags to use</param>
/// <returns>Number of bytes received</returns>
public virtual int CrosReceive(ref byte[] buffer, SocketFlags socketFlags)
{
byte[] lengthBytes = new byte[4];
base.Receive(lengthBytes, socketFlags);
int dataSize = BitConverter.ToInt32(lengthBytes, 0);
Array.Resize(ref buffer, dataSize);
return base.Receive(buffer, socketFlags);
}
开发者ID:rubendal,项目名称:CrosSocket,代码行数:14,代码来源:CrosSocket.cs
示例12: Send_internal
private static int Send_internal(IntPtr sock,
byte[] buf, int offset,
int count,
SocketFlags flags,
out int error)
{
throw new System.NotImplementedException();
}
开发者ID:desunit,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:Socket_2_1.Mosa.cs
示例13: UDPClient
/// <summary>
/// Initializes a new instance of the <see cref="UDPClient"/> class.
/// </summary>
/// <param name="ep">The ep.</param>
public UDPClient(IPAddress IPAddress, UInt16 Port, Boolean Broadcast = false, SocketFlags Socketflags = SocketFlags.None)
: this(Broadcast, Socketflags)
{
this.InternalIPAddress = IPAddress;
this.InternalPort = Port;
InternalSocket.Connect(new IPEndPoint(IPAddress, Port));
}
开发者ID:Vanaheimr,项目名称:Nyi,代码行数:12,代码来源:UDPClient.cs
示例14: Send
public int Send(byte[] data, int offset, int length, SocketFlags flags) {
lock (this) {
if (_shuttedDown_Send)
return 0;
else
return _socket.Send(data, offset, length, flags);
}
}
开发者ID:Ricordanza,项目名称:poderosa,代码行数:8,代码来源:channel.cs
示例15: SendToAsync
/// <summary>
/// Sends data asynchronously to a specific remote host
/// </summary>
/// <param name="socket">socket</param>
/// <param name="buffer">an array of type System.Byte that contains the data to send</param>
/// <param name="offset">the zero-based position in buffer at which to begin sending data</param>
/// <param name="size">the number of bytes to send</param>
/// <param name="flags">a bitwise combination of the System.Net.Sockets.SocketFlags values.</param>
/// <param name="remoteEP">an System.Net.EndPoint that represents the remote device</param>
/// <returns>Task</returns>
public static Task SendToAsync(this Socket socket, byte[] buffer, int offset, int size, SocketFlags flags, EndPoint remoteEP)
{
return Task<int>.Factory.FromAsync(
(ac, state) => socket.BeginSendTo(buffer, offset, size, flags, remoteEP, ac, state),
socket.EndSendTo,
null,
TaskCreationOptions.None);
}
开发者ID:kakone,项目名称:SSDP.Portable,代码行数:18,代码来源:SocketExtensions.cs
示例16: Send
public static SocketError Send(this UDPClient UDPClient, String UDPPacketString, Encoding Encoding = null, SocketFlags SocketFlags = SocketFlags.None)
{
if (Encoding == null)
Encoding = Encoding.UTF8;
var UDPPacketData = Encoding.GetBytes(UDPPacketString);
return UDPClient.Send(UDPPacketData, SocketFlags);
}
开发者ID:subbuballa,项目名称:Hermod,代码行数:9,代码来源:UDPExtensions.cs
示例17: SetUnmanagedStructures
//
// SetUnmanagedStructures -
// Fills in Overlapped Structures used in an Async Overlapped Winsock call
// these calls are outside the runtime and are unmanaged code, so we need
// to prepare specific structures and ints that lie in unmanaged memory
// since the Overlapped calls can be Async
//
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, SocketAddress socketAddress, SocketFlags socketFlags)
{
m_MessageBuffer = new byte[s_WSAMsgSize];
m_WSABufferArray = new byte[s_WSABufferSize];
//ipv4 or ipv6?
IPAddress ipAddress = (socketAddress.Family == AddressFamily.InterNetworkV6
? socketAddress.GetIPAddress() : null);
bool ipv4 = (((Socket)AsyncObject).AddressFamily == AddressFamily.InterNetwork
|| (ipAddress != null && ipAddress.IsIPv4MappedToIPv6)); // DualMode
bool ipv6 = ((Socket)AsyncObject).AddressFamily == AddressFamily.InterNetworkV6;
//prepare control buffer
if (ipv4) {
m_ControlBuffer = new byte[s_ControlDataSize];
}
else if (ipv6) {
m_ControlBuffer = new byte[s_ControlDataIPv6Size];
}
//pin buffers
object[] objectsToPin = new object[(m_ControlBuffer != null)?5:4];
objectsToPin[0] = buffer;
objectsToPin[1] = m_MessageBuffer;
objectsToPin[2] = m_WSABufferArray;
//prepare socketaddress buffer
m_SocketAddress = socketAddress;
m_SocketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[3] = m_SocketAddress.m_Buffer;
if(m_ControlBuffer != null){
objectsToPin[4] = m_ControlBuffer;
}
base.SetUnmanagedStructures(objectsToPin);
//prepare data buffer
m_WSABuffer = (WSABuffer*) Marshal.UnsafeAddrOfPinnedArrayElement(m_WSABufferArray, 0);
m_WSABuffer->Length = size;
m_WSABuffer->Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
//setup structure
m_Message = (UnsafeNclNativeMethods.OSSOCK.WSAMsg*) Marshal.UnsafeAddrOfPinnedArrayElement(m_MessageBuffer, 0);
m_Message->socketAddress = Marshal.UnsafeAddrOfPinnedArrayElement(m_SocketAddress.m_Buffer,0);
m_Message->addressLength = (uint)m_SocketAddress.Size;
m_Message->buffers = Marshal.UnsafeAddrOfPinnedArrayElement(m_WSABufferArray,0);
m_Message->count = 1;
if(m_ControlBuffer != null){
m_Message->controlBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(m_ControlBuffer, 0);
m_Message->controlBuffer.Length = m_ControlBuffer.Length;
}
m_Message->flags = socketFlags;
}
开发者ID:REALTOBIZ,项目名称:mono,代码行数:65,代码来源:_ReceiveMessageOverlappedAsyncResult.cs
示例18: ToClientObserver
public static IObserver<ByteBuffer> ToClientObserver(this Socket socket, int size, SocketFlags socketFlags)
{
return Observer.Create<ByteBuffer>(async buffer =>
{
var sent = 0;
while (sent < buffer.Length)
sent += await socket.SendAsync(buffer.Bytes, sent, buffer.Length - sent, socketFlags);
});
}
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:9,代码来源:ClientExtensions.cs
示例19: SetUnmanagedStructures
// SetUnmanagedStructures
//
// Fills in overlapped Structures used in an async overlapped Winsock call.
// These calls are outside the runtime and are unmanaged code, so we need
// to prepare specific structures and ints that lie in unmanaged memory
// since the overlapped calls may complete asynchronously.
internal void SetUnmanagedStructures(byte[] buffer, int offset, int size, Internals.SocketAddress socketAddress, SocketFlags socketFlags)
{
_messageBuffer = new byte[s_wsaMsgSize];
_wsaBufferArray = new byte[s_wsaBufferSize];
bool ipv4, ipv6;
Socket.GetIPProtocolInformation(((Socket)AsyncObject).AddressFamily, socketAddress, out ipv4, out ipv6);
// Prepare control buffer.
if (ipv4)
{
_controlBuffer = new byte[s_controlDataSize];
}
else if (ipv6)
{
_controlBuffer = new byte[s_controlDataIPv6Size];
}
// Pin buffers.
object[] objectsToPin = new object[(_controlBuffer != null) ? 5 : 4];
objectsToPin[0] = buffer;
objectsToPin[1] = _messageBuffer;
objectsToPin[2] = _wsaBufferArray;
// Prepare socketaddress buffer.
_socketAddress = socketAddress;
_socketAddress.CopyAddressSizeIntoBuffer();
objectsToPin[3] = _socketAddress.Buffer;
if (_controlBuffer != null)
{
objectsToPin[4] = _controlBuffer;
}
base.SetUnmanagedStructures(objectsToPin);
// Prepare data buffer.
_wsaBuffer = (WSABuffer*)Marshal.UnsafeAddrOfPinnedArrayElement(_wsaBufferArray, 0);
_wsaBuffer->Length = size;
_wsaBuffer->Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, offset);
// Setup structure.
_message = (Interop.Winsock.WSAMsg*)Marshal.UnsafeAddrOfPinnedArrayElement(_messageBuffer, 0);
_message->socketAddress = Marshal.UnsafeAddrOfPinnedArrayElement(_socketAddress.Buffer, 0);
_message->addressLength = (uint)_socketAddress.Size;
_message->buffers = Marshal.UnsafeAddrOfPinnedArrayElement(_wsaBufferArray, 0);
_message->count = 1;
if (_controlBuffer != null)
{
_message->controlBuffer.Pointer = Marshal.UnsafeAddrOfPinnedArrayElement(_controlBuffer, 0);
_message->controlBuffer.Length = _controlBuffer.Length;
}
_message->flags = socketFlags;
}
开发者ID:noahfalk,项目名称:corefx,代码行数:63,代码来源:ReceiveMessageOverlappedAsyncResult.Windows.cs
示例20: ToFrameClientObserver
public static IObserver<DisposableByteBuffer> ToFrameClientObserver(this Socket socket, SocketFlags socketFlags, CancellationToken token)
{
return Observer.Create<DisposableByteBuffer>(async managedBuffer =>
{
var headerBuffer = BitConverter.GetBytes(managedBuffer.Length);
await socket.SendCompletelyAsync(headerBuffer, headerBuffer.Length, socketFlags, token);
await socket.SendCompletelyAsync(managedBuffer.Bytes, managedBuffer.Length, socketFlags, token);
});
}
开发者ID:tleviathan,项目名称:JetBlack.Network,代码行数:9,代码来源:FrameClientExtensions.cs
注:本文中的SocketFlags类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论