diff options
author | Daniel Stenberg <daniel@haxx.se> | 2008-05-12 21:43:24 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2008-05-12 21:43:24 +0000 |
commit | 514592b89207e83d13b5a4e79bc247aa6f74c4b7 (patch) | |
tree | 9c9df12cf0f9b8f5e2aa835c4379ae7be9e3805d /lib/connect.c | |
parent | d72efff878a352e24d3a7cc8cf7c2f8b0b65f409 (diff) |
- Introducing curl_easy_send() and curl_easy_recv(). They can be used to send
and receive data over a connection previously setup with curl_easy_perform()
and its CURLOPT_CONNECT_ONLY option. The sendrecv.c example was added to
show how they can be used.
Diffstat (limited to 'lib/connect.c')
-rw-r--r-- | lib/connect.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/lib/connect.c b/lib/connect.c index 33e4e0777..74380da1e 100644 --- a/lib/connect.c +++ b/lib/connect.c @@ -92,6 +92,7 @@ #include "sockaddr.h" /* required for Curl_sockaddr_storage */ #include "inet_ntop.h" #include "inet_pton.h" +#include "sslgen.h" /* for Curl_ssl_check_cxn() */ /* The last #include file should be: */ #include "memdebug.h" @@ -977,3 +978,46 @@ CURLcode Curl_connecthost(struct connectdata *conn, /* context */ return CURLE_OK; } + +/* + * Used to extract socket and connectdata struct for the most recent + * transfer on the given SessionHandle. + * + * The socket 'long' will be -1 in case of failure! + */ +CURLcode Curl_getconnectinfo(struct SessionHandle *data, + long *param_longp, + struct connectdata **connp) +{ + if((data->state.lastconnect != -1) && + (data->state.connc->connects[data->state.lastconnect] != NULL)) { + struct connectdata *c = + data->state.connc->connects[data->state.lastconnect]; + if(connp) + /* only store this if the caller cares for it */ + *connp = c; + *param_longp = c->sock[FIRSTSOCKET]; + /* we have a socket connected, let's determine if the server shut down */ + /* determine if ssl */ + if(c->ssl[FIRSTSOCKET].use) { + /* use the SSL context */ + if(!Curl_ssl_check_cxn(c)) + *param_longp = -1; /* FIN received */ + } +/* Minix 3.1 doesn't support any flags on recv; just assume socket is OK */ +#ifdef MSG_PEEK + else { + /* use the socket */ + char buf; + if(recv((RECV_TYPE_ARG1)c->sock[FIRSTSOCKET], (RECV_TYPE_ARG2)&buf, + (RECV_TYPE_ARG3)1, (RECV_TYPE_ARG4)MSG_PEEK) == 0) { + *param_longp = -1; /* FIN received */ + } + } +#endif + } + else + *param_longp = -1; + + return CURLE_OK; +} |