public void CloseSocket() { uint method = 0x2cb; this.TrEntry(method); try { base.RequestSendLock(); lock (this.Lock) { if (this.network != null) { this.network.Close(); this.network = null; } this.connected = false; if ((this.socket != null) && this.socket.Connected) { this.socket.Shutdown(SocketShutdown.Both); this.socket.Close(); } this.socket = null; base.TrText("Socket closed "); } } finally { base.ReleaseSendLock(); base.TrExit(method); } }
private Socket ConnectSocket(string localAddr, string connectionName, int options) { uint method = 0x2c8; this.TrEntry(method, new object[] { localAddr, connectionName, options }); Socket socket = null; IPAddress[] hostAddresses = null; try { string str; int num2; int length = connectionName.Length; int index = connectionName.IndexOf('(', 0); if (index >= 0) { string str2; str = connectionName.Substring(0, index); int num4 = connectionName.IndexOf(')', index); if (num4 < 0) { str2 = connectionName.Substring(index + 1); } else { str2 = connectionName.Substring(index + 1, (num4 - index) - 1); } num2 = Convert.ToInt32(str2); if ((num2 < 0) || (num2 > 0xffff)) { throw new MQManagedClientException(0x20009203, (uint)num2, (uint)num2, "'" + connectionName + "'", "TCP/IP", " (Convert.ToInt32)", 2, 0x893); } } else { str = connectionName.Trim(); num2 = 0x586; } try { ParsedLocalAddr addr = this.ParseLocalAddress(localAddr); hostAddresses = Dns.GetHostAddresses(str); Exception exception = null; bool flag = "MQIPADDR_IPV6".Equals(Convert.ToString(base.env.Cfg.GetStringValue(MQClientCfg.ENV_MQIPADDRV)).ToUpper()); IPAddress address = null; foreach (IPAddress address2 in hostAddresses) { if ((flag && address2.AddressFamily.Equals(AddressFamily.InterNetworkV6)) || (!flag && address2.AddressFamily.Equals(AddressFamily.InterNetwork))) { address = address2; try { socket = this.ConnectUsingLocalAddr(addr, address2, num2); } catch (Exception exception2) { base.TrException(method, exception2, 1); exception = exception2; } break; } } foreach (IPAddress address3 in hostAddresses) { if (address3 != address) { try { socket = this.ConnectUsingLocalAddr(addr, address3, num2); break; } catch (Exception exception3) { base.TrException(method, exception3, 2); exception = exception3; } } } if (socket == null) { throw exception; } if ((base.clientConn.SSLCipherSpec != null) && (base.clientConn.SSLCipherSpec.Length > 0)) { this.network = new MQEncryptedSocket(base.env, this, socket, this.mqcd, this.sslConfigOptions); } else { this.network = new MQPlainSocket(base.env, this, socket); } this.connected = true; } catch (Exception exception4) { uint errorCode; base.TrException(method, exception4, 3); if (exception4 is SocketException) { errorCode = (uint)((SocketException)exception4).ErrorCode; } else { errorCode = 0; } throw new MQManagedClientException(0x20009202, errorCode, errorCode, connectionName, "TCP/IP", " (Exception)", 2, 0x9ea); } } finally { base.TrExit(method); } return(socket); }