1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-21 07:38:49 -05:00

keep 'socktype' in the connectdata struct and make sure we use that for all

protocol sockets even if the resolved address may say otherwise
This commit is contained in:
Daniel Stenberg 2005-09-16 21:30:08 +00:00
parent d0a4104c0c
commit e7093b3ca8
7 changed files with 22 additions and 21 deletions

View File

@ -631,8 +631,9 @@ singleipconnect(struct connectdata *conn,
int error;
bool conected;
struct SessionHandle *data = conn->data;
curl_socket_t sockfd = socket(ai->ai_family, ai->ai_socktype,
ai->ai_protocol);
curl_socket_t sockfd;
sockfd = socket(ai->ai_family, conn->socktype, ai->ai_protocol);
if (sockfd == CURL_SOCKET_BAD)
return CURL_SOCKET_BAD;
@ -661,12 +662,11 @@ singleipconnect(struct connectdata *conn,
Curl_nonblock(sockfd, TRUE);
/* Connect TCP sockets, bind UDP */
if(ai->ai_socktype==SOCK_STREAM) {
if(conn->socktype == SOCK_STREAM)
rc = connect(sockfd, ai->ai_addr, (socklen_t)ai->ai_addrlen);
} else {
else
rc = 0;
}
if(-1 == rc) {
error = Curl_ourerrno();

View File

@ -858,7 +858,7 @@ static CURLcode ftp_state_use_port(struct connectdata *conn,
* Workaround for AIX5 getaddrinfo() problem (it doesn't set ai_socktype):
*/
if (ai->ai_socktype == 0)
ai->ai_socktype = SOCK_STREAM;
ai->ai_socktype = conn->socktype;
portsock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
if (portsock == CURL_SOCKET_BAD) {

View File

@ -423,10 +423,10 @@ Curl_addrinfo *Curl_he2ai(struct hostent *he, int port)
prevai->ai_next = ai;
ai->ai_family = AF_INET; /* we only support this */
if(port == PORT_TFTP)
ai->ai_socktype = SOCK_DGRAM;
else
ai->ai_socktype = SOCK_STREAM;
/* we return all names as STREAM, so when using this address for TFTP
the type must be ignored and conn->socktype be used instead! */
ai->ai_socktype = SOCK_STREAM;
ai->ai_addrlen = sizeof(struct sockaddr_in);
/* make the ai_addr point to the address immediately following this struct

View File

@ -252,10 +252,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
memset(&hints, 0, sizeof(hints));
hints.ai_family = pf;
if(conn->protocol & PROT_TFTP)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
hints.ai_socktype = conn->socktype;
hints.ai_flags = ai_flags;
snprintf(sbuf, sizeof(sbuf), "%d", port);

View File

@ -559,7 +559,10 @@ static bool init_resolve_thread (struct connectdata *conn,
*/
thread_and_event[0] = td->thread_hnd;
thread_and_event[1] = td->event_thread_started;
if (WaitForMultipleObjects(sizeof(thread_and_event) / sizeof(thread_and_event[0]), thread_and_event, FALSE, INFINITE) == WAIT_FAILED) {
if (WaitForMultipleObjects(sizeof(thread_and_event) /
sizeof(thread_and_event[0]),
thread_and_event, FALSE,
INFINITE) == WAIT_FAILED) {
/* The resolver thread has been created,
* most probably it works now - ignoring this "minor" error
*/
@ -804,10 +807,7 @@ Curl_addrinfo *Curl_getaddrinfo(struct connectdata *conn,
memset(&hints, 0, sizeof(hints));
hints.ai_family = pf;
if(conn->protocol & PROT_TFTP)
hints.ai_socktype = SOCK_DGRAM;
else
hints.ai_socktype = SOCK_STREAM;
hints.ai_socktype = conn->socktype;
hints.ai_flags = AI_CANONNAME;
itoa(port, sbuf, 10);

View File

@ -2729,6 +2729,8 @@ static CURLcode CreateConnection(struct SessionHandle *data,
* Setup internals depending on protocol
*************************************************************/
conn->socktype = SOCK_STREAM; /* most of them are TCP streams */
if (strequal(conn->protostr, "HTTP")) {
#ifndef CURL_DISABLE_HTTP
conn->port = PORT_HTTP;
@ -2927,12 +2929,13 @@ static CURLcode CreateConnection(struct SessionHandle *data,
else if (strequal(conn->protostr, "TFTP")) {
#ifndef CURL_DISABLE_TFTP
char *type;
conn->socktype = SOCK_DGRAM; /* UDP datagram based */
conn->protocol |= PROT_TFTP;
conn->port = PORT_TFTP;
conn->remote_port = PORT_TFTP;
conn->curl_connect = Curl_tftp_connect;
conn->curl_do = Curl_tftp;
conn->curl_done = Curl_tftp_done;
conn->curl_done = Curl_tftp_done;
/* TFTP URLs support an extension like ";mode=<typecode>" that
* we'll try to get now! */
type=strstr(conn->path, ";mode=");

View File

@ -562,6 +562,7 @@ struct connectdata {
char *ip_addr_str;
char protostr[16]; /* store the protocol string in this buffer */
int socktype; /* SOCK_STREAM or SOCK_DGRAM */
struct hostname host;
struct hostname proxy;