imap-send: use separate read and write fds
This is a patch that enables us to use the run-command API, which is supported on Windows. Signed-off-by: Erik Faye-Lund <kusmabite@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Erik Faye-Lund committed
Oct 19, 2009 at 17:42 UTC
7a7796e9a7cd8f789fa964acbb1eec5efd05436a
1 file changed
+23
-14
imap-send.c
+23
-14
@@ -151,7 +151,7 @@ struct imap_list {
151
};
152
153
struct imap_socket {
154
- int fd;
154
+ int fd[2];
155
SSL *ssl;
156
};
157
@@ -301,8 +301,12 @@ static int ssl_socket_connect(struct imap_socket *sock, int use_tls_only, int ve
301
ssl_socket_perror("SSL_new");
302
return -1;
303
}
304
- if (!SSL_set_fd(sock->ssl, sock->fd)) {
305
- ssl_socket_perror("SSL_set_fd");
304
+ if (!SSL_set_rfd(sock->ssl, sock->fd[0])) {
305
+ ssl_socket_perror("SSL_set_rfd");
306
+ return -1;
307
+ }
308
+ if (!SSL_set_wfd(sock->ssl, sock->fd[1])) {
309
+ ssl_socket_perror("SSL_set_wfd");
310
return -1;
311
}
312
@@ -324,11 +328,12 @@ static int socket_read(struct imap_socket *sock, char *buf, int len)
328
n = SSL_read(sock->ssl, buf, len);
329
else
330
#endif
327
- n = xread(sock->fd, buf, len);
331
+ n = xread(sock->fd[0], buf, len);
332
if (n <= 0) {
333
socket_perror("read", sock, n);
330
- close(sock->fd);
331
- sock->fd = -1;
334
+ close(sock->fd[0]);
335
+ close(sock->fd[1]);
336
+ sock->fd[0] = sock->fd[1] = -1;
337
}
338
return n;
339
}
@@ -341,11 +346,12 @@ static int socket_write(struct imap_socket *sock, const char *buf, int len)
346
n = SSL_write(sock->ssl, buf, len);
347
else
348
#endif
344
- n = write_in_full(sock->fd, buf, len);
349
+ n = write_in_full(sock->fd[1], buf, len);
350
if (n != len) {
351
socket_perror("write", sock, n);
347
- close(sock->fd);
348
- sock->fd = -1;
352
+ close(sock->fd[0]);
353
+ close(sock->fd[1]);
354
+ sock->fd[0] = sock->fd[1] = -1;
355
}
356
return n;
357
}
@@ -358,7 +364,8 @@ static void socket_shutdown(struct imap_socket *sock)
364
SSL_free(sock->ssl);
365
}
366
#endif
361
- close(sock->fd);
367
+ close(sock->fd[0]);
368
+ close(sock->fd[1]);
369
}
370
371
/* simple line buffering */
@@ -911,7 +918,7 @@ static void imap_close_server(struct imap_store *ictx)
918
{
919
struct imap *imap = ictx->imap;
920
914
- if (imap->buf.sock.fd != -1) {
921
+ if (imap->buf.sock.fd[0] != -1) {
922
imap_exec(ictx, NULL, "LOGOUT");
923
socket_shutdown(&imap->buf.sock);
924
}
@@ -939,7 +946,7 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
946
ctx = xcalloc(sizeof(*ctx), 1);
947
948
ctx->imap = imap = xcalloc(sizeof(*imap), 1);
942
- imap->buf.sock.fd = -1;
949
+ imap->buf.sock.fd[0] = imap->buf.sock.fd[1] = -1;
950
imap->in_progress_append = &imap->in_progress;
951
952
/* open connection to IMAP server */
@@ -966,7 +973,8 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
973
974
close(a[0]);
975
969
- imap->buf.sock.fd = a[1];
976
+ imap->buf.sock.fd[0] = a[1];
977
+ imap->buf.sock.fd[1] = dup(a[1]);
978
979
imap_info("ok\n");
980
} else {
@@ -1043,7 +1051,8 @@ static struct store *imap_open_store(struct imap_server_conf *srvc)
1051
goto bail;
1052
}
1053
1046
- imap->buf.sock.fd = s;
1054
+ imap->buf.sock.fd[0] = s;
1055
+ imap->buf.sock.fd[1] = dup(s);
1056
1057
if (srvc->use_ssl &&
1058
ssl_socket_connect(&imap->buf.sock, 0, srvc->ssl_verify)) {