mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 14:23:30 +01:00
remember; tor_socket_errno has side effects!
svn:r2997
This commit is contained in:
parent
9449ff7336
commit
f77ff938b7
@ -582,6 +582,10 @@ void tor_mutex_release(tor_mutex_t *m)
|
|||||||
* get your errors from WSAGetLastError, not errno. (If you supply a
|
* get your errors from WSAGetLastError, not errno. (If you supply a
|
||||||
* socket of -1, we check WSAGetLastError, but don't correct
|
* socket of -1, we check WSAGetLastError, but don't correct
|
||||||
* WSAEWOULDBLOCKs.)
|
* WSAEWOULDBLOCKs.)
|
||||||
|
*
|
||||||
|
* The upshot of all of this is that when a socket call fails, you
|
||||||
|
* should call tor_socket_errno <em>at most once</em> on the failing
|
||||||
|
* socket to get the error.
|
||||||
*/
|
*/
|
||||||
#ifdef MS_WINDOWS
|
#ifdef MS_WINDOWS
|
||||||
int tor_socket_errno(int sock)
|
int tor_socket_errno(int sock)
|
||||||
|
@ -184,7 +184,8 @@ int read_to_buf(int s, size_t at_most, buf_t *buf, int *reached_eof) {
|
|||||||
// log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most);
|
// log_fn(LOG_DEBUG,"reading at most %d bytes.",at_most);
|
||||||
read_result = recv(s, buf->mem+buf->datalen, at_most, 0);
|
read_result = recv(s, buf->mem+buf->datalen, at_most, 0);
|
||||||
if (read_result < 0) {
|
if (read_result < 0) {
|
||||||
if(!ERRNO_IS_EAGAIN(tor_socket_errno(s))) { /* it's a real error */
|
int e = tor_socket_errno(s);
|
||||||
|
if(!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0; /* would block. */
|
return 0; /* would block. */
|
||||||
@ -254,7 +255,8 @@ int flush_buf(int s, buf_t *buf, size_t *buf_flushlen)
|
|||||||
|
|
||||||
write_result = send(s, buf->mem, *buf_flushlen, 0);
|
write_result = send(s, buf->mem, *buf_flushlen, 0);
|
||||||
if (write_result < 0) {
|
if (write_result < 0) {
|
||||||
if(!ERRNO_IS_EAGAIN(tor_socket_errno(s))) { /* it's a real error */
|
int e = tor_socket_errno(s);
|
||||||
|
if(!ERRNO_IS_EAGAIN(e)) { /* it's a real error */
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
log_fn(LOG_DEBUG,"write() would block, returning.");
|
log_fn(LOG_DEBUG,"write() would block, returning.");
|
||||||
|
@ -538,10 +538,11 @@ int connection_connect(connection_t *conn, char *address, uint32_t addr, uint16_
|
|||||||
log_fn(LOG_DEBUG,"Connecting to %s:%u.",address,port);
|
log_fn(LOG_DEBUG,"Connecting to %s:%u.",address,port);
|
||||||
|
|
||||||
if(connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0) {
|
if(connect(s,(struct sockaddr *)&dest_addr,sizeof(dest_addr)) < 0) {
|
||||||
if(!ERRNO_IS_CONN_EINPROGRESS(tor_socket_errno(s))) {
|
int e = tor_socket_errno(s);
|
||||||
|
if(!ERRNO_IS_CONN_EINPROGRESS(e)) {
|
||||||
/* yuck. kill it. */
|
/* yuck. kill it. */
|
||||||
log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port,
|
log_fn(LOG_INFO,"Connect() to %s:%u failed: %s",address,port,
|
||||||
tor_socket_strerror(tor_socket_errno(s)));
|
tor_socket_strerror(e));
|
||||||
tor_close_socket(s);
|
tor_close_socket(s);
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -869,11 +869,11 @@ static int do_main_loop(void) {
|
|||||||
|
|
||||||
/* let catch() handle things like ^c, and otherwise don't worry about it */
|
/* let catch() handle things like ^c, and otherwise don't worry about it */
|
||||||
if (poll_result < 0) {
|
if (poll_result < 0) {
|
||||||
|
int e = tor_socket_errno(-1);
|
||||||
/* let the program survive things like ^z */
|
/* let the program survive things like ^z */
|
||||||
if(tor_socket_errno(-1) != EINTR) {
|
if(e != EINTR) {
|
||||||
log_fn(LOG_ERR,"poll failed: %s [%d]",
|
log_fn(LOG_ERR,"poll failed: %s [%d]",
|
||||||
tor_socket_strerror(tor_socket_errno(-1)),
|
tor_socket_strerror(e), e);
|
||||||
tor_socket_errno(-1));
|
|
||||||
return -1;
|
return -1;
|
||||||
} else {
|
} else {
|
||||||
log_fn(LOG_DEBUG,"poll interrupted.");
|
log_fn(LOG_DEBUG,"poll interrupted.");
|
||||||
|
Loading…
Reference in New Issue
Block a user