}
if (session->sock) {
- sock_close(session->sock);
+ sock_close(session->sock, TRUE);
session->sock = NULL;
session->state = SESSION_DISCONNECTED;
debug_print("session (%p): closed\n", session);
return bp - buf;
}
-gint sock_close(SockInfo *sock)
+gint sock_close(SockInfo *sock, gboolean close_fd)
{
gint ret;
g_source_remove(sock->g_source);
sock->g_source = 0;
#endif
+ if (close_fd) {
#ifdef G_OS_WIN32
- shutdown(sock->sock, 1); /* complete transfer before close */
- ret = closesocket(sock->sock);
+ shutdown(sock->sock, 1); /* complete transfer before close */
+ ret = closesocket(sock->sock);
#else
- ret = fd_close(sock->sock);
+ ret = fd_close(sock->sock);
+ }
#endif
g_free(sock->canonical_name);
gint sock_read (SockInfo *sock, gchar *buf, gint len);
gint sock_write (SockInfo *sock, const gchar *buf, gint len);
gint sock_write_all (SockInfo *sock, const gchar *buf, gint len);
-gint sock_close (SockInfo *sock);
+gint sock_close (SockInfo *sock, gboolean close_fd);
/* Functions to directly work on FD. They are needed for pipes */
gint fd_connect_unix (const gchar *path);
return MAILIMAP_ERROR_CONNECTION_REFUSED;
if (proxy_connect(sock, server, port, proxy_info) < 0) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return MAILIMAP_ERROR_CONNECTION_REFUSED;
}
stream = mailstream_socket_open_timeout(sock->sock,
imap->imap_timeout);
if (stream == NULL) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return MAILIMAP_ERROR_MEMORY;
}
+ /* Libetpan now has the socket fd, and we're not interested in
+ * rest of the SockInfo struct. Let's free it, while not touching
+ * the socket itself. */
+ sock_close(sock, FALSE);
+
return mailimap_connect(imap, stream);
}
if (proxy_connect(sock, server, port, proxy_info) < 0) {
debug_print("Can not make proxy connection via %s:%d\n",
proxy_info->proxy_host, proxy_info->proxy_port);
- sock_close(sock);
+ sock_close(sock, TRUE);
return MAILIMAP_ERROR_CONNECTION_REFUSED;
}
stream = mailstream_ssl_open_with_callback_timeout(sock->sock,
imap->imap_timeout, callback, data);
if (stream == NULL) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return MAILIMAP_ERROR_SSL;
}
+ /* Libetpan now has the socket fd, and we're not interested in
+ * rest of the SockInfo struct. Let's free it, while not touching
+ * the socket itself. */
+ sock_close(sock, FALSE);
+
return mailimap_connect(imap, stream);
}
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
if (proxy_connect(sock, server, port, proxy_info) < 0) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
}
stream = mailstream_socket_open_timeout(sock->sock,
imap->nntp_timeout);
if (stream == NULL) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return NEWSNNTP_ERROR_MEMORY;
}
+ /* Libetpan now has the socket fd, and we're not interested in
+ * rest of the SockInfo struct. Let's free it, while not touching
+ * the socket itself. */
+ sock_close(sock, FALSE);
+
return newsnntp_connect(imap, stream);
}
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
if (proxy_connect(sock, server, port, proxy_info) < 0) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return NEWSNNTP_ERROR_CONNECTION_REFUSED;
}
stream = mailstream_ssl_open_with_callback_timeout(sock->sock,
imap->nntp_timeout, callback, data);
if (stream == NULL) {
- sock_close(sock);
+ sock_close(sock, TRUE);
return NEWSNNTP_ERROR_SSL;
}
+ /* Libetpan now has the socket fd, and we're not interested in
+ * rest of the SockInfo struct. Let's free it, while not touching
+ * the socket itself. */
+ sock_close(sock, FALSE);
+
return newsnntp_connect(imap, stream);
}
if(sock == NULL || sock->state == CONN_FAILED) {
debug_print("Could not connect to LCDd\n");
if(sock && sock->state == CONN_FAILED) {
- sock_close(sock);
+ sock_close(sock, TRUE);
sock = NULL;
}
return;
#ifndef G_OS_WIN32
shutdown(sock->sock, SHUT_RDWR);
#endif
- sock_close(sock);
+ sock_close(sock, TRUE);
sock = NULL;
}
}