- struct linger linger;
-
- if (IsConnected())
- Close();
-
- m_fd = socket(addr_man.GetFamily(), SOCK_STREAM, 0);
-
- if (m_fd < 0)
- return FALSE;
-
- m_connected = FALSE;
-
- linger.l_onoff = 1;
- linger.l_linger = 5;
- setsockopt(m_fd, SOL_SOCKET, SO_LINGER, (char*)&linger, sizeof(linger));
-
- // Stay in touch with the state of things...
-
- unsigned long flag = 1;
- setsockopt(m_fd, SOL_SOCKET, SO_KEEPALIVE, (char*)&flag, sizeof(int));
-
- // Disable the nagle algorithm, which delays sends till the
- // buffer is full (or a certain time period has passed?)...
-
-#if defined(__WINDOWS__) || (defined(IPPROTO_TCP) && defined(TCP_NODELAY))
- flag = 1;
- setsockopt(m_fd, IPPROTO_TCP, TCP_NODELAY, (char*)&flag, sizeof(int));
-#endif
-
- struct sockaddr *remote;
- size_t len;
-
- addr_man.Build(remote, len);
-
- if (connect(m_fd, remote, len) != 0)
- return FALSE;
-
- if (!(m_flags & SPEED))
- {
- flag = 1;
- ioctl(m_fd, FIONBIO, &flag);
- }
-
- Notify(TRUE);
-
- m_connected = TRUE;
- return TRUE;