protected static void acceptConnections() { string serverFull = "SERVERFULL"; bool decSuccess = false; Cipher.Encrypt(serverFull, p, out serverFull, out decSuccess); while (listening) { bool except = false; listener.Stop(); listener.Start(1); try { listenSocket = listener.AcceptSocket(); } catch (Exception listenEx) { except = true; } if (listenSocket.Connected) { if (clients < maxClients) { ClientClass c = new ClientClass(); SocketInformation info = new SocketInformation(); c.clientSocket = listenSocket; c.clientSocket.ReceiveTimeout = 10; byte[] bbuffer = new byte[65535]; c.clientSocket.Receive(bbuffer); string nick = ASCIIEncoding.Default.GetString(bbuffer); nick = nick.Substring(0, nick.IndexOf('\0')); decSuccess = false; Cipher.Decrypt(nick, p, out nick, out decSuccess); c.nick = nick.Substring(4, nick.IndexOf("x") - 4); c.state = 1; clientList.Add(c); clients++; outputToConsole("added client " + (clients) + ": " + c.nick + " on endpoint " + listenSocket.RemoteEndPoint.ToString() + "\r\n"); string response = "SEED" + seed + "SIZE" + size + "END"; Cipher.Encrypt(response, p, out response, out decSuccess); c.clientSocket.Send(ASCIIEncoding.Default.GetBytes(response)); } else { listenSocket.Send(ASCIIEncoding.Default.GetBytes(serverFull)); } } } outputToConsole("\r\n\r\nExiting...\r\n"); closeListeners(); }
public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType) { SafeCloseSocket handle; Interop.Winsock.WSAPROTOCOL_INFO protocolInfo; fixed (byte* pinnedBuffer = socketInformation.ProtocolInformation) { handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer); protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFO)Marshal.PtrToStructure<Interop.Winsock.WSAPROTOCOL_INFO>((IntPtr)pinnedBuffer); } if (handle.IsInvalid) { SocketException e = new SocketException(); if (e.SocketErrorCode == SocketError.InvalidArgument) { throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation"); } else { throw e; } } addressFamily = protocolInfo.iAddressFamily; socketType = (SocketType)protocolInfo.iSocketType; protocolType = (ProtocolType)protocolInfo.iProtocol; return handle; }
public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType) { SafeCloseSocket handle; Interop.Winsock.WSAPROTOCOL_INFO protocolInfo; fixed(byte *pinnedBuffer = socketInformation.ProtocolInformation) { handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer); protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFO)Marshal.PtrToStructure <Interop.Winsock.WSAPROTOCOL_INFO>((IntPtr)pinnedBuffer); } if (handle.IsInvalid) { SocketException e = new SocketException(); if (e.SocketErrorCode == SocketError.InvalidArgument) { throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation"); } else { throw e; } } addressFamily = protocolInfo.iAddressFamily; socketType = (SocketType)protocolInfo.iSocketType; protocolType = (ProtocolType)protocolInfo.iProtocol; return(handle); }
public SocketConnection(uint pSockID, SocketInformation socketInformation_0) : base(socketInformation_0) { this.bool_0 = false; this.uint_0 = pSockID; this.string_0 = base.RemoteEndPoint.ToString().Split(new char[] { ':' })[0]; }
public Socket(ns.SocketInformation socketInformation) : base(socketInformation) { lock (_socklist) { _socklist.Add(FD, this); } //EDB.WriteLine("Making socket w/ FD=" + FD); }
public MusConnection(SocketInformation socketInformation) : base(socketInformation) { _buffer = new byte[512]; _asyncOnReceive = OnReceive; WaitForData(); }
public SocketConnection(uint uint_1, SocketInformation socketInformation_0) : base(socketInformation_0) { this.uint_0 = uint_1; this.string_0 = base.RemoteEndPoint.ToString().Split(new char[] { ':' })[0]; }
public Socket(ns.SocketInformation socketInformation) : base(socketInformation) { if (_socklist == null) { _socklist = new SortedList <uint, Socket>(); } _socklist.Add(FD, this); //EDB.WriteLine("Making socket w/ FD=" + FD); }
internal void HandleNewConnection(SocketInformation connectioninfo, int PreconnID) { TcpConnection connection = new TcpConnection(Convert.ToUInt32(PreconnID), connectioninfo); this.Connections[PreconnID] = connection; PhoenixEnvironment.GetGame().GetClientManager().CreateAndStartClient((uint)PreconnID, ref connection); if (PhoenixEnvironment.GetConfig().data["emu.messages.connections"] == "1") { Logging.WriteLine(string.Concat(new object[] { ">> Connection [", PreconnID, "] from [", connection.ipAddress, "]" })); } }
public SocketClient(SocketInformation Info) : base(Info) { this.Client = new Client(this); this.ArrayBuffer = new byte[ARRAY_BUFFER_SIZE]; base.Blocking = false; ReceiveCallback = new AsyncCallback(EndReceiving); SendCallback = new AsyncCallback(EndSending); }
internal void method_5(SocketInformation socketInformation_0, int int_0) { SocketConnection Message = new SocketConnection(Convert.ToUInt32(int_0), socketInformation_0); this.Message1_0[int_0] = Message; GoldTree.GetGame().GetClientManager().method_8((uint)int_0, ref Message); if (GoldTree.GetConfig().data["emu.messages.connections"] == "1") { Logging.WriteLine(string.Concat(new object[] { ">> Connection [", int_0, "] from [", Message.String_0, "]" })); } }
protected virtual void ProcessSocket(SocketInformation info) { using (var psk = new Socket(info)) { int len = 0; var buf = new byte[4096]; while (true) { try { if (psk.Available > 0) { len = psk.Receive(buf); if (len < 1) { break; } } else { break; } } catch (Exception ex) { log.e(ex); } } string response = $@"HTTP/1.0 200 OK Connection:close Content-Type:text/html; charset=utf-8 <html><body>{AppDomain.CurrentDomain.FriendlyName}</body></html> "; UTF8Encoding en = new UTF8Encoding(); var bytes = en.GetBytes(response); psk.Send(bytes); } }
public MdoSocket(SocketInformation socketInformation) : base(socketInformation) { allDone = new ManualResetEvent(false); }
public Socket(SocketInformation socketInformation) { throw new NotImplementedException(); }
public static unsafe SocketError CreateSocket( SocketInformation socketInformation, out SafeSocketHandle socket, ref AddressFamily addressFamily, ref SocketType socketType, ref ProtocolType protocolType) { if (socketInformation.ProtocolInformation == null || socketInformation.ProtocolInformation.Length < sizeof(Interop.Winsock.WSAPROTOCOL_INFOW)) { throw new ArgumentException(SR.net_sockets_invalid_socketinformation, nameof(socketInformation)); } Interop.Winsock.EnsureInitialized(); fixed(byte *protocolInfoBytes = socketInformation.ProtocolInformation) { // Sockets are non-inheritable in .NET Core. // Handle properties like HANDLE_FLAG_INHERIT are not cloned with socket duplication, therefore // we need to disable handle inheritance when constructing the new socket handle from Protocol Info. // Additionally, it looks like WSA_FLAG_NO_HANDLE_INHERIT has no effect when being used with the Protocol Info // variant of WSASocketW, so it is being passed to that call only for consistency. // Inheritance is being disabled with SetHandleInformation(...) after the WSASocketW call. IntPtr handle = Interop.Winsock.WSASocketW( (AddressFamily)(-1), (SocketType)(-1), (ProtocolType)(-1), (IntPtr)protocolInfoBytes, 0, Interop.Winsock.SocketConstructorFlags.WSA_FLAG_OVERLAPPED | Interop.Winsock.SocketConstructorFlags.WSA_FLAG_NO_HANDLE_INHERIT); socket = new SafeSocketHandle(handle, ownsHandle: true); if (socket.IsInvalid) { SocketError error = GetLastSocketError(); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Error(null, $"WSASocketW failed with error {error}"); } socket.Dispose(); return(error); } if (!Interop.Kernel32.SetHandleInformation(socket, Interop.Kernel32.HandleFlags.HANDLE_FLAG_INHERIT, 0)) { // Returning SocketError for consistency, since the call site can deal with conversion, and // the most common SetHandleInformation error (AccessDenied) is included in SocketError anyways: SocketError error = GetLastSocketError(); if (NetEventSource.Log.IsEnabled()) { NetEventSource.Error(null, $"SetHandleInformation failed with error {error}"); } socket.Dispose(); return(error); } if (NetEventSource.Log.IsEnabled()) { NetEventSource.Info(null, socket); } Interop.Winsock.WSAPROTOCOL_INFOW *protocolInfo = (Interop.Winsock.WSAPROTOCOL_INFOW *)protocolInfoBytes; addressFamily = protocolInfo->iAddressFamily; socketType = protocolInfo->iSocketType; protocolType = protocolInfo->iProtocol; return(SocketError.Success); } }
public Socket(SocketInformation socketInformation) { }
public CipheredCrosSocket(SocketInformation socketInformation) : base(socketInformation) { }
public static unsafe SafeCloseSocket CreateSocket(SocketInformation socketInformation, out AddressFamily addressFamily, out SocketType socketType, out ProtocolType protocolType) { throw new PlatformNotSupportedException(); }
public Socket (SocketInformation socketInformation) { var options = socketInformation.Options; islistening = (options & SocketInformationOptions.Listening) != 0; connected = (options & SocketInformationOptions.Connected) != 0; blocking = (options & SocketInformationOptions.NonBlocking) == 0; useoverlappedIO = (options & SocketInformationOptions.UseOnlyOverlappedIO) != 0; var result = Mono.DataConverter.Unpack ("iiiil", socketInformation.ProtocolInformation, 0); address_family = (AddressFamily) (int) result [0]; socket_type = (SocketType) (int) result [1]; protocol_type = (ProtocolType) (int) result [2]; isbound = (ProtocolType) (int) result [3] != 0; socket = (IntPtr) (long) result [4]; SocketDefaults (); }
public TcpDuplicateContext(System.Net.Sockets.SocketInformation socketInformation, Uri via, byte[] readData) : base(via, readData) { this.socketInformation = socketInformation; }
/// <summary> /// Initializes a new instance of the <see cref="T:System.Net.Sockets.Socket"/> class using the specified value returned from <see cref="M:System.Net.Sockets.Socket.DuplicateAndClose(System.Int32)"/>. /// </summary> /// <param name="socketInformation">The socket information returned by <see cref="M:System.Net.Sockets.Socket.DuplicateAndClose(System.Int32)"/>.</param> public unsafe Socket(SocketInformation socketInformation) { Socket.s_LoggingEnabled = Logging.On; if (Socket.s_LoggingEnabled) Logging.Enter(Logging.Sockets, (object) this, "Socket", (object) this.addressFamily); ExceptionHelper.UnrestrictedSocketPermission.Demand(); Socket.InitializeSockets(); if (socketInformation.ProtocolInformation == null || socketInformation.ProtocolInformation.Length < Socket.protocolInformationSize) throw new ArgumentException(SR.GetString("net_sockets_invalid_socketinformation"), "socketInformation.ProtocolInformation"); fixed (byte* pinnedBuffer = socketInformation.ProtocolInformation) { this.m_Handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer); UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO wsaprotocolInfo = (UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO) Marshal.PtrToStructure((IntPtr) ((void*) pinnedBuffer), typeof (UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO)); this.addressFamily = wsaprotocolInfo.iAddressFamily; this.socketType = (SocketType) wsaprotocolInfo.iSocketType; this.protocolType = (ProtocolType) wsaprotocolInfo.iProtocol; } if (this.m_Handle.IsInvalid) { SocketException socketException = new SocketException(); if (socketException.ErrorCode == 10022) throw new ArgumentException(SR.GetString("net_sockets_invalid_socketinformation"), "socketInformation"); else throw socketException; } else { if (this.addressFamily != AddressFamily.InterNetwork && this.addressFamily != AddressFamily.InterNetworkV6) throw new NotSupportedException(SR.GetString("net_invalidversion")); this.m_IsConnected = socketInformation.IsConnected; this.willBlock = !socketInformation.IsNonBlocking; this.InternalSetBlocking(this.willBlock); this.isListening = socketInformation.IsListening; this.UseOnlyOverlappedIO = socketInformation.UseOnlyOverlappedIO; if (socketInformation.RemoteEndPoint != null) { this.m_RightEndPoint = socketInformation.RemoteEndPoint; this.m_RemoteEndPoint = socketInformation.RemoteEndPoint; } else { EndPoint endPoint = (EndPoint) null; if (this.addressFamily == AddressFamily.InterNetwork) endPoint = (EndPoint) IPEndPoint.Any; else if (this.addressFamily == AddressFamily.InterNetworkV6) endPoint = (EndPoint) IPEndPoint.IPv6Any; SocketAddress socketAddress = endPoint.Serialize(); SocketError socketError; try { socketError = UnsafeNclNativeMethods.OSSOCK.getsockname(this.m_Handle, socketAddress.m_Buffer, out socketAddress.m_Size); } catch (ObjectDisposedException ex) { socketError = SocketError.NotSocket; } if (socketError == SocketError.Success) { try { this.m_RightEndPoint = endPoint.Create(socketAddress); } catch { } } } if (!Socket.s_LoggingEnabled) return; Logging.Exit(Logging.Sockets, (object) this, "Socket", (string) null); } }
public Socket(SocketInformation socketInformation) { s_loggingEnabled = Logging.On; if (s_loggingEnabled) { Logging.Enter(Logging.Sockets, this, "Socket", _addressFamily); } InitializeSockets(); if (socketInformation.ProtocolInformation == null || socketInformation.ProtocolInformation.Length < SocketPal.ProtocolInformationSize) { throw new ArgumentException(SR.net_sockets_invalid_socketinformation, "socketInformation.ProtocolInformation"); } _handle = SocketPal.CreateSocket(socketInformation, out _addressFamily, out _socketType, out _protocolType); if (_addressFamily != AddressFamily.InterNetwork && _addressFamily != AddressFamily.InterNetworkV6) { throw new NotSupportedException(SR.net_invalidversion); } _isConnected = socketInformation.IsConnected; _willBlock = !socketInformation.IsNonBlocking; InternalSetBlocking(_willBlock); _isListening = socketInformation.IsListening; // Are we bound? If so, what's the local endpoint? if (socketInformation.RemoteEndPoint != null) { _rightEndPoint = socketInformation.RemoteEndPoint; _remoteEndPoint = socketInformation.RemoteEndPoint; } else { EndPoint ep = null; if (_addressFamily == AddressFamily.InterNetwork) { ep = IPEndPointStatics.Any; } else if (_addressFamily == AddressFamily.InterNetworkV6) { ep = IPEndPointStatics.IPv6Any; } Internals.SocketAddress socketAddress = IPEndPointExtensions.Serialize(ep); SocketError errorCode; try { errorCode = SocketPal.GetSockName( _handle, socketAddress.Buffer, ref socketAddress.InternalSize); } catch (ObjectDisposedException) { errorCode = SocketError.NotSocket; } if (errorCode == SocketError.Success) { try { // We're bound. Set _rightEndPoint accordingly. _rightEndPoint = ep.Create(socketAddress); } catch { } } } if (s_loggingEnabled) { Logging.Exit(Logging.Sockets, this, "Socket", null); } }
public SocketInformation DuplicateAndClose (int targetProcessId) { var si = new SocketInformation (); si.Options = (is_listening ? SocketInformationOptions.Listening : 0) | (is_connected ? SocketInformationOptions.Connected : 0) | (is_blocking ? 0 : SocketInformationOptions.NonBlocking) | (use_overlapped_io ? SocketInformationOptions.UseOnlyOverlappedIO : 0); si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", (int)address_family, (int)socket_type, (int)protocol_type, is_bound ? 1 : 0, (long)Handle); safe_handle = null; return si; }
public bool Open(byte[] socketInformationBytes) { try { SocketInformation SI = new SocketInformation(); SI.ProtocolInformation = socketInformationBytes; SI.Options = new SocketInformationOptions(); SI.Options = SocketInformationOptions.Connected; _Socket = new Socket(SI); _Socket.Blocking = true; if (_Socket.Connected) _Stream = new NetworkStream(_Socket); return _Socket.Connected; } catch (SocketException sex) { RMLog.Exception(sex, "SocketException in TcpConnection::Open(). ErrorCode=" + sex.ErrorCode.ToString()); return false; } catch (Exception ex) { RMLog.Exception(ex, "Exception in TcpConnection::Open()"); return false; } }
public bool Open(int ASocketHandle) { if (OSUtils.IsWindows) { try { NativeMethods.WSAData WSA = new NativeMethods.WSAData(); SocketError Result = NativeMethods.WSAStartup((short)0x0202, out WSA); if (Result != SocketError.Success) throw new SocketException(NativeMethods.WSAGetLastError()); SocketPermission SP = new SocketPermission(System.Security.Permissions.PermissionState.Unrestricted); SP.Demand(); SocketInformation SI = new SocketInformation(); SI.Options = SocketInformationOptions.Connected; SI.ProtocolInformation = new byte[Marshal.SizeOf(typeof(NativeMethods.WSAPROTOCOL_INFO))]; Result = SocketError.Success; unsafe { fixed (byte* pinnedBuffer = SI.ProtocolInformation) { Result = NativeMethods.WSADuplicateSocket(new IntPtr(ASocketHandle), (uint)Process.GetCurrentProcess().Id, pinnedBuffer); } } if (Result != SocketError.Success) throw new SocketException(NativeMethods.WSAGetLastError()); return Open(new Socket(SI)); } catch (SocketException sex) { RMLog.Exception(sex, "SocketException in TcpConnection::Open(). ErrorCode=" + sex.ErrorCode.ToString()); return false; } catch (Exception ex) { RMLog.Exception(ex, "Exception in TcpConnection::Open()"); return false; } } else { try { SocketInformation SI = new SocketInformation(); SI.Options = SocketInformationOptions.Connected; SI.ProtocolInformation = new byte[24]; // From Mono's Socket.cs DuplicateAndClose() SI.ProtocolInformation = Mono.DataConverter.Pack("iiiil", (int)address_family, (int)socket_type, (int)protocol_type, isbound ? 1 : 0, (long)socket); byte[] B1 = BitConverter.GetBytes((int)AddressFamily.InterNetwork); byte[] B2 = BitConverter.GetBytes((int)SocketType.Stream); byte[] B3 = BitConverter.GetBytes((int)ProtocolType.Tcp); byte[] B4 = BitConverter.GetBytes((int)1); byte[] B5 = BitConverter.GetBytes((long)ASocketHandle); Array.Copy(B1, 0, SI.ProtocolInformation, 0, B1.Length); Array.Copy(B2, 0, SI.ProtocolInformation, 4, B2.Length); Array.Copy(B3, 0, SI.ProtocolInformation, 8, B3.Length); Array.Copy(B4, 0, SI.ProtocolInformation, 12, B4.Length); Array.Copy(B5, 0, SI.ProtocolInformation, 16, B5.Length); return Open(new Socket(SI)); } catch (SocketException sex) { RMLog.Exception(sex, "SocketException in TcpConnection::Open(). ErrorCode=" + sex.ErrorCode.ToString()); return false; } catch (Exception ex) { RMLog.Exception(ex, "Exception in TcpConnection::Open()"); return false; } } }
/// <summary> /// Duplicates the socket reference for the target process, and closes the socket for this process. /// </summary> /// /// <returns> /// The socket reference to be passed to the target process. /// </returns> /// <param name="targetProcessId">The ID of the target process where a duplicate of the socket reference is created.</param><exception cref="T:System.Net.Sockets.SocketException"><paramref name="targetProcessID"/> is not a valid process id.-or- Duplication of the socket reference failed. </exception> public unsafe SocketInformation DuplicateAndClose(int targetProcessId) { if (Socket.s_LoggingEnabled) Logging.Enter(Logging.Sockets, (object) this, "DuplicateAndClose", (string) null); if (this.CleanedUp) throw new ObjectDisposedException(this.GetType().FullName); ExceptionHelper.UnrestrictedSocketPermission.Demand(); SocketInformation socketInformation = new SocketInformation(); socketInformation.ProtocolInformation = new byte[Socket.protocolInformationSize]; SocketError socketError; fixed (byte* pinnedBuffer = socketInformation.ProtocolInformation) socketError = (SocketError) UnsafeNclNativeMethods.OSSOCK.WSADuplicateSocket(this.m_Handle, (uint) targetProcessId, pinnedBuffer); if (socketError != SocketError.Success) { SocketException socketException = new SocketException(); if (Socket.s_LoggingEnabled) Logging.Exception(Logging.Sockets, (object) this, "DuplicateAndClose", (Exception) socketException); throw socketException; } else { socketInformation.IsConnected = this.Connected; socketInformation.IsNonBlocking = !this.Blocking; socketInformation.IsListening = this.isListening; socketInformation.UseOnlyOverlappedIO = this.UseOnlyOverlappedIO; socketInformation.RemoteEndPoint = this.m_RemoteEndPoint; this.Close(-1); if (Socket.s_LoggingEnabled) Logging.Exit(Logging.Sockets, (object) this, "DuplicateAndClose", (string) null); return socketInformation; } }
public Socket(SocketInformation socketInformation) { s_LoggingEnabled = Logging.On; if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "Socket", addressFamily); ExceptionHelper.UnrestrictedSocketPermission.Demand(); InitializeSockets(); if(socketInformation.ProtocolInformation == null || socketInformation.ProtocolInformation.Length < protocolInformationSize){ throw new ArgumentException(SR.GetString(SR.net_sockets_invalid_socketinformation), "socketInformation.ProtocolInformation"); } unsafe{ fixed(byte * pinnedBuffer = socketInformation.ProtocolInformation){ m_Handle = SafeCloseSocket.CreateWSASocket(pinnedBuffer); UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO protocolInfo = (UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO)Marshal.PtrToStructure((IntPtr)pinnedBuffer, typeof(UnsafeNclNativeMethods.OSSOCK.WSAPROTOCOL_INFO)); addressFamily = protocolInfo.iAddressFamily; socketType = (SocketType)protocolInfo.iSocketType; protocolType = (ProtocolType)protocolInfo.iProtocol; } } if (m_Handle.IsInvalid) { SocketException e = new SocketException(); if(e.ErrorCode == (int)SocketError.InvalidArgument){ throw new ArgumentException(SR.GetString(SR.net_sockets_invalid_socketinformation), "socketInformation"); } else { throw e; } } if (addressFamily != AddressFamily.InterNetwork && addressFamily != AddressFamily.InterNetworkV6) { throw new NotSupportedException(SR.GetString(SR.net_invalidversion)); } m_IsConnected = socketInformation.IsConnected; willBlock = !socketInformation.IsNonBlocking; InternalSetBlocking(willBlock); isListening = socketInformation.IsListening; UseOnlyOverlappedIO = socketInformation.UseOnlyOverlappedIO; //are we bound? if so, what's the local endpoint? if (socketInformation.RemoteEndPoint != null) { m_RightEndPoint = socketInformation.RemoteEndPoint; m_RemoteEndPoint = socketInformation.RemoteEndPoint; } else { EndPoint ep = null; if (addressFamily == AddressFamily.InterNetwork ) { ep = IPEndPoint.Any; } else if(addressFamily == AddressFamily.InterNetworkV6) { ep = IPEndPoint.IPv6Any; } SocketAddress socketAddress = ep.Serialize(); SocketError errorCode; try { errorCode = UnsafeNclNativeMethods.OSSOCK.getsockname( m_Handle, socketAddress.m_Buffer, ref socketAddress.m_Size); } catch (ObjectDisposedException) { errorCode = SocketError.NotSocket; } if (errorCode == SocketError.Success) { try { //we're bound m_RightEndPoint = ep.Create(socketAddress); } catch { } } } if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "Socket", null); }
public TcpDuplicateContext(SocketInformation socketInformation, Uri via, byte[] readData) : base(via, readData) { this.socketInformation = socketInformation; }
public SocketInformation DuplicateAndClose(int targetProcessId){ if(s_LoggingEnabled)Logging.Enter(Logging.Sockets, this, "DuplicateAndClose", null); if (CleanedUp) { throw new ObjectDisposedException(GetType().FullName); } ExceptionHelper.UnrestrictedSocketPermission.Demand(); SocketInformation info = new SocketInformation(); info.ProtocolInformation = new byte[protocolInformationSize]; // This can throw ObjectDisposedException. SocketError errorCode; #if !FEATURE_PAL unsafe { fixed (byte* pinnedBuffer = info.ProtocolInformation) { errorCode = (SocketError) UnsafeNclNativeMethods.OSSOCK.WSADuplicateSocket(m_Handle, (uint)targetProcessId, pinnedBuffer); } } #else errorCode = SocketError.SocketError; #endif // !FEATURE_PAL if (errorCode!=SocketError.Success) { SocketException socketException = new SocketException(); if(s_LoggingEnabled)Logging.Exception(Logging.Sockets, this, "DuplicateAndClose", socketException); throw socketException; } info.IsConnected = Connected; info.IsNonBlocking = !Blocking; info.IsListening = isListening; info.UseOnlyOverlappedIO = UseOnlyOverlappedIO; info.RemoteEndPoint = m_RemoteEndPoint; //make sure we don't shutdown, etc. Close(-1); if(s_LoggingEnabled)Logging.Exit(Logging.Sockets, this, "DuplicateAndClose", null); return info; }
internal void ConnectFromSocket(SocketInformation si) { Socket s = new Socket(si); ConnectFromSocket(s); }
public SocketInformation DuplicateAndClose (int targetProcessId) { var si = new SocketInformation (); si.Options = (islistening ? SocketInformationOptions.Listening : 0) | (connected ? SocketInformationOptions.Connected : 0) | (blocking ? 0 : SocketInformationOptions.NonBlocking) | (useoverlappedIO ? SocketInformationOptions.UseOnlyOverlappedIO : 0); si.ProtocolInformation = Mono.DataConverter.Pack ("iiiil", (int)address_family, (int)socket_type, (int)protocol_type, isbound ? 1 : 0, (long)socket); socket = (IntPtr) (-1); return si; }
public RSocket( SocketInformation socketinformation ) : base(socketinformation) { }
public void Start(SocketInformation info) { SetEncoding(Encoding.ASCII); _SockInfo = info; _Sock = new Socket(info); }
public Socket (SocketInformation socketInformation) { throw new NotImplementedException ("SocketInformation not figured out yet"); // ifdef to avoid the warnings. #if false //address_family = socketInformation.address_family; //socket_type = socketInformation.socket_type; //protocol_type = socketInformation.protocol_type; address_family = AddressFamily.InterNetwork; socket_type = SocketType.Stream; protocol_type = ProtocolType.IP; int error; socket = Socket_internal (address_family, socket_type, protocol_type, out error); if (error != 0) throw new SocketException (error); SocketDefaults (); #endif }
public Socket (SocketInformation socketInformation) { this.is_listening = (socketInformation.Options & SocketInformationOptions.Listening) != 0; this.is_connected = (socketInformation.Options & SocketInformationOptions.Connected) != 0; this.is_blocking = (socketInformation.Options & SocketInformationOptions.NonBlocking) == 0; this.use_overlapped_io = (socketInformation.Options & SocketInformationOptions.UseOnlyOverlappedIO) != 0; var result = Mono.DataConverter.Unpack ("iiiil", socketInformation.ProtocolInformation, 0); this.address_family = (AddressFamily) (int) result [0]; this.socket_type = (SocketType) (int) result [1]; this.protocol_type = (ProtocolType) (int) result [2]; this.is_bound = (ProtocolType) (int) result [3] != 0; this.safe_handle = new SafeSocketHandle ((IntPtr) (long) result [4], true); SocketDefaults (); }
public SocketWrap(SocketInformation socketInformation) { UnderlyingObject = new Socket(socketInformation); }
public Socket(SocketInformation socketInformation) { // This constructor works in conjunction with DuplicateAndClose, which is not supported on Unix. // See comments in DuplicateAndClose. throw new PlatformNotSupportedException(SR.net_sockets_duplicateandclose_notsupported); }
static void Main( string[] args ) { #if DEBUG Console.WriteLine("PID {0} Debug", Process.GetCurrentProcess().Id ); #else Console.WriteLine("PID {0} Release", Process.GetCurrentProcess().Id ); #endif if (!args.Any(arg=>arg.StartsWith("--original="))) { // Assume we're the original process OriginalPath = Assembly.GetExecutingAssembly().GetName().CodeBase; // Relaunch and quit so that we don't lock the original executable: Relaunch(); return; } OriginalPath = args.First(arg=>arg.StartsWith("--original=")).Remove(0,"--original=".Length); if (args.Any(arg=>arg.StartsWith("--pipe="))) { var pipename = args.First(arg=>arg.StartsWith("--pipe=")).Remove(0,"--pipe=".Length); var pipe = new AnonymousPipeClientStream(pipename); var buffer = new byte[9001]; int read=0, length=0; do { read = pipe.Read(buffer,length,buffer.Length-length); length += read; } while ( read!=0 ); var si = new SocketInformation() { Options = SocketInformationOptions.Connected | SocketInformationOptions.UseOnlyOverlappedIO , ProtocolInformation = buffer.Take(length).ToArray() }; Connection = IrcConnection.RecoverConnectionFrom( new Socket(si) ); } else { Connection = new IrcConnection( "irc.afternet.org", 6667 ); } Connection.Listeners.Add(new CommandResponder(){State=Connection.Listeners[0] as IrcConnectionState}); Connection.BeginPumping(); Connection.WaitPumping(); if ( RelaunchFlag ) Relaunch(); }