Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
aa828c1b
Commit
aa828c1b
authored
Jun 30, 2008
by
Eric Wong
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
http: split out logic around getaddrinfo() and connect()
Makes code easier to read and modularize git-svn-id:
https://svn.musicpd.org/mpd/trunk@7388
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
ec1eeeea
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
38 deletions
+40
-38
inputStream_http.c
src/inputStream_http.c
+40
-38
No files found.
src/inputStream_http.c
View file @
aa828c1b
...
@@ -276,18 +276,13 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
...
@@ -276,18 +276,13 @@ static int parseUrl(InputStreamHTTPData * data, char *url)
return
0
;
return
0
;
}
}
static
int
initHTTPConnection
(
InputStream
*
inStream
)
/* returns -1 on error, 0 on success (and sets dest) */
static
int
my_getaddrinfo
(
struct
addrinfo
**
dest
,
const
char
*
host
,
const
char
*
port
)
{
{
char
*
connHost
;
char
*
connPort
;
struct
addrinfo
*
ans
=
NULL
;
struct
addrinfo
*
ap
=
NULL
;
struct
addrinfo
hints
;
struct
addrinfo
hints
;
int
error
;
int
error
;
InputStreamHTTPData
*
data
=
(
InputStreamHTTPData
*
)
inStream
->
data
;
/**
* Setup hints
*/
hints
.
ai_flags
=
0
;
hints
.
ai_flags
=
0
;
hints
.
ai_family
=
PF_UNSPEC
;
hints
.
ai_family
=
PF_UNSPEC
;
hints
.
ai_socktype
=
SOCK_STREAM
;
hints
.
ai_socktype
=
SOCK_STREAM
;
...
@@ -297,50 +292,57 @@ static int initHTTPConnection(InputStream * inStream)
...
@@ -297,50 +292,57 @@ static int initHTTPConnection(InputStream * inStream)
hints
.
ai_canonname
=
NULL
;
hints
.
ai_canonname
=
NULL
;
hints
.
ai_next
=
NULL
;
hints
.
ai_next
=
NULL
;
if
(
proxyHost
)
{
if
((
error
=
getaddrinfo
(
host
,
port
,
&
hints
,
dest
)))
{
connHost
=
proxyHost
;
DEBUG
(
__FILE__
": Error getting address info for %s:%s: %s
\n
"
,
connPort
=
proxyPort
;
host
,
port
,
gai_strerror
(
error
));
}
else
{
connHost
=
data
->
host
;
connPort
=
data
->
port
;
}
error
=
getaddrinfo
(
connHost
,
connPort
,
&
hints
,
&
ans
);
if
(
error
)
{
DEBUG
(
__FILE__
": Error getting address info: %s
\n
"
,
gai_strerror
(
error
));
return
-
1
;
return
-
1
;
}
}
return
0
;
}
/* returns the fd we connected to, or -1 on error */
static
int
my_connect_addrs
(
struct
addrinfo
*
ans
)
{
int
fd
;
struct
addrinfo
*
ap
;
/* loop through possible addresses */
/* loop through possible addresses */
for
(
ap
=
ans
;
ap
!=
NULL
;
ap
=
ap
->
ai_next
)
{
for
(
ap
=
ans
;
ap
!=
NULL
;
ap
=
ap
->
ai_next
)
{
if
((
data
->
sock
=
socket
(
ap
->
ai_family
,
ap
->
ai_socktype
,
fd
=
socket
(
ap
->
ai_family
,
ap
->
ai_socktype
,
ap
->
ai_protocol
);
ap
->
ai_protocol
))
<
0
)
{
if
(
fd
<
0
)
{
DEBUG
(
__FILE__
": unable to
connec
t: %s
\n
"
,
DEBUG
(
__FILE__
": unable to
get socke
t: %s
\n
"
,
strerror
(
errno
));
strerror
(
errno
));
freeaddrinfo
(
ans
);
continue
;
return
-
1
;
}
}
set_nonblocking
(
data
->
sock
);
set_nonblocking
(
fd
);
if
(
connect
(
fd
,
ap
->
ai_addr
,
ap
->
ai_addrlen
)
>=
0
||
errno
==
EINPROGRESS
)
return
fd
;
/* success */
if
(
connect
(
data
->
sock
,
ap
->
ai_addr
,
ap
->
ai_addrlen
)
>=
0
DEBUG
(
__FILE__
": unable to connect: %s
\n
"
,
strerror
(
errno
));
||
errno
==
EINPROGRESS
)
{
xclose
(
fd
);
/* failed, get the next one */
data
->
connState
=
HTTP_CONN_STATE_INIT
;
data
->
buflen
=
0
;
freeaddrinfo
(
ans
);
return
0
;
/* success */
}
}
return
-
1
;
}
/* failed, get the next one */
static
int
initHTTPConnection
(
InputStream
*
inStream
)
{
struct
addrinfo
*
ans
=
NULL
;
InputStreamHTTPData
*
data
=
(
InputStreamHTTPData
*
)
inStream
->
data
;
DEBUG
(
__FILE__
": unable to connect: %s
\n
"
,
strerror
(
errno
));
if
((
proxyHost
?
my_getaddrinfo
(
&
ans
,
proxyHost
,
proxyPort
)
:
close
(
data
->
sock
);
my_getaddrinfo
(
&
ans
,
data
->
host
,
data
->
port
))
<
0
)
}
return
-
1
;
data
->
sock
=
my_connect_addrs
(
ans
);
freeaddrinfo
(
ans
);
freeaddrinfo
(
ans
);
if
(
data
->
sock
<
0
)
return
-
1
;
/* failed */
return
-
1
;
/* failed */
data
->
connState
=
HTTP_CONN_STATE_INIT
;
data
->
buflen
=
0
;
return
0
;
}
}
static
int
finishHTTPInit
(
InputStream
*
inStream
)
static
int
finishHTTPInit
(
InputStream
*
inStream
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment