mirror of
https://github.com/moparisthebest/curl
synced 2025-02-28 17:31:46 -05:00
examples: socket type cleanup
This commit is contained in:
parent
f0aad0089e
commit
bcfb9ea34c
@ -367,7 +367,7 @@ static int init_fifo (GlobalInfo *g)
|
|||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
static const char *fifo = "hiper.fifo";
|
static const char *fifo = "hiper.fifo";
|
||||||
int sockfd;
|
curl_socket_t sockfd;
|
||||||
|
|
||||||
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
|
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
|
||||||
if ( lstat (fifo, &st) == 0 )
|
if ( lstat (fifo, &st) == 0 )
|
||||||
|
@ -350,7 +350,7 @@ static int init_fifo (GlobalInfo *g)
|
|||||||
{
|
{
|
||||||
struct stat st;
|
struct stat st;
|
||||||
static const char *fifo = "hiper.fifo";
|
static const char *fifo = "hiper.fifo";
|
||||||
int sockfd;
|
curl_socket_t sockfd;
|
||||||
|
|
||||||
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
|
fprintf(MSG_OUT, "Creating named pipe \"%s\"\n", fifo);
|
||||||
if (lstat (fifo, &st) == 0) {
|
if (lstat (fifo, &st) == 0) {
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
#include <curl/curl.h>
|
#include <curl/curl.h>
|
||||||
|
|
||||||
/* Auxiliary function that waits on the socket. */
|
/* Auxiliary function that waits on the socket. */
|
||||||
static int wait_on_socket(int sockfd, int for_recv, long timeout_ms)
|
static int wait_on_socket(curl_socket_t sockfd, int for_recv, long timeout_ms)
|
||||||
{
|
{
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
fd_set infd, outfd, errfd;
|
fd_set infd, outfd, errfd;
|
||||||
@ -49,7 +49,8 @@ int main(void)
|
|||||||
CURLcode res;
|
CURLcode res;
|
||||||
/* Minimalistic http request */
|
/* Minimalistic http request */
|
||||||
const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n";
|
const char *request = "GET / HTTP/1.0\r\nHost: example.com\r\n\r\n";
|
||||||
int sockfd; /* socket */
|
curl_socket_t sockfd; /* socket */
|
||||||
|
long sockextr;
|
||||||
size_t iolen;
|
size_t iolen;
|
||||||
|
|
||||||
curl = curl_easy_init();
|
curl = curl_easy_init();
|
||||||
@ -65,9 +66,11 @@ int main(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Extract the socket from the curl handle - we'll need it
|
/* Extract the socket from the curl handle - we'll need it for waiting.
|
||||||
* for waiting */
|
* Note that this API takes a pointer to a 'long' while we use
|
||||||
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockfd);
|
* curl_socket_t for sockets otherwise.
|
||||||
|
*/
|
||||||
|
res = curl_easy_getinfo(curl, CURLINFO_LASTSOCKET, &sockextr);
|
||||||
|
|
||||||
if(CURLE_OK != res)
|
if(CURLE_OK != res)
|
||||||
{
|
{
|
||||||
@ -75,6 +78,8 @@ int main(void)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sockfd = sockextr;
|
||||||
|
|
||||||
/* wait for the socket to become ready for sending */
|
/* wait for the socket to become ready for sending */
|
||||||
if(!wait_on_socket(sockfd, 0, 60000L))
|
if(!wait_on_socket(sockfd, 0, 60000L))
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user