memdebug: trace send, recv and socket

... to allow them to be included in torture tests too.

closes #1980
This commit is contained in:
Daniel Stenberg 2017-10-10 16:56:35 +02:00
parent 4af3c777a9
commit ad164eceb3
No known key found for this signature in database
GPG key ID: 5CC908FDB71E12C2
5 changed files with 73 additions and 18 deletions

View file

@ -343,7 +343,12 @@ curl_socket_t curl_socket(int domain, int type, int protocol,
"FD %s:%d socket() = %ld\n" :
"FD %s:%d socket() = %zd\n";
curl_socket_t sockfd = socket(domain, type, protocol);
curl_socket_t sockfd;
if(countcheck("socket", line, source))
return CURL_SOCKET_BAD;
sockfd = socket(domain, type, protocol);
if(source && (sockfd != CURL_SOCKET_BAD))
curl_memlog(fmt, source, line, sockfd);
@ -351,6 +356,32 @@ curl_socket_t curl_socket(int domain, int type, int protocol,
return sockfd;
}
ssize_t curl_dosend(int sockfd, const void *buf, size_t len, int flags,
int line, const char *source)
{
ssize_t rc;
if(countcheck("send", line, source))
return -1;
rc = send(sockfd, buf, len, flags);
if(source)
curl_memlog("SEND %s:%d send(%zu) = %zd\n",
source, line, len, rc);
return rc;
}
ssize_t curl_dorecv(int sockfd, void *buf, size_t len, int flags,
int line, const char *source)
{
ssize_t rc;
if(countcheck("recv", line, source))
return -1;
rc = recv(sockfd, buf, len, flags);
if(source)
curl_memlog("RECV %s:%d recv(%zu) = %zd\n",
source, line, len, rc);
return rc;
}
#ifdef HAVE_SOCKETPAIR
int curl_socketpair(int domain, int type, int protocol,
curl_socket_t socket_vector[2],

View file

@ -8,7 +8,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
* Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al.
*
* This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms
@ -66,6 +66,12 @@ CURL_EXTERN int curl_socketpair(int domain, int type, int protocol,
int line, const char *source);
#endif
/* send/receive sockets */
CURL_EXTERN ssize_t curl_dosend(int sockfd, const void *buf, size_t len,
int flags, int line, const char *source);
CURL_EXTERN ssize_t curl_dorecv(int sockfd, void *buf, size_t len, int flags,
int line, const char *source);
/* FILE functions */
CURL_EXTERN FILE *curl_fopen(const char *file, const char *mode, int line,
const char *source);
@ -84,6 +90,8 @@ CURL_EXTERN int curl_fclose(FILE *file, int line, const char *source);
#define calloc(nbelem,size) curl_docalloc(nbelem, size, __LINE__, __FILE__)
#define realloc(ptr,size) curl_dorealloc(ptr, size, __LINE__, __FILE__)
#define free(ptr) curl_dofree(ptr, __LINE__, __FILE__)
#define send(a,b,c,d) curl_dosend(a,b,c,d, __LINE__, __FILE__)
#define recv(a,b,c,d) curl_dorecv(a,b,c,d, __LINE__, __FILE__)
#ifdef WIN32
# ifdef UNICODE

View file

@ -677,7 +677,7 @@ ldapsb_tls_read(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
ber_slen_t ret;
CURLcode err = CURLE_RECV_ERROR;
ret = li->recv(conn, FIRSTSOCKET, buf, len, &err);
ret = (li->recv)(conn, FIRSTSOCKET, buf, len, &err);
if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK);
}
@ -692,7 +692,7 @@ ldapsb_tls_write(Sockbuf_IO_Desc *sbiod, void *buf, ber_len_t len)
ber_slen_t ret;
CURLcode err = CURLE_SEND_ERROR;
ret = li->send(conn, FIRSTSOCKET, buf, len, &err);
ret = (li->send)(conn, FIRSTSOCKET, buf, len, &err);
if(ret < 0 && err == CURLE_AGAIN) {
SET_SOCKERRNO(EWOULDBLOCK);
}