Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cta
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
dCache
cta
Commits
8700deb0
Commit
8700deb0
authored
8 years ago
by
Steven Murray
Browse files
Options
Downloads
Patches
Plain Diff
Improved error message of connectWithTimeout()
parent
2df42c45
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tapeserver/castor/io/io.cpp
+44
-26
44 additions, 26 deletions
tapeserver/castor/io/io.cpp
with
44 additions
and
26 deletions
tapeserver/castor/io/io.cpp
+
44
−
26
View file @
8700deb0
...
...
@@ -840,38 +840,56 @@ int castor::io::connectWithTimeout(
const
unsigned
short
port
,
const
int
timeout
)
throw
(
castor
::
exception
::
TimeOut
,
castor
::
exception
::
Exception
)
{
std
::
ostringstream
portStream
;
portStream
<<
port
;
struct
addrinfo
hints
;
memset
(
&
hints
,
'\0'
,
sizeof
(
hints
));
hints
.
ai_family
=
AF_INET
;
hints
.
ai_socktype
=
SOCK_STREAM
;
try
{
std
::
ostringstream
portStream
;
portStream
<<
port
;
struct
addrinfo
hints
;
memset
(
&
hints
,
'\0'
,
sizeof
(
hints
));
hints
.
ai_family
=
AF_INET
;
hints
.
ai_socktype
=
SOCK_STREAM
;
struct
addrinfo
*
res
=
NULL
;
{
const
int
rc
=
getaddrinfo
(
hostName
.
c_str
(),
portStream
.
str
().
c_str
(),
&
hints
,
&
res
);
// If getaddrinfo() returned a negative value
if
(
0
!=
rc
)
{
char
errBuf
[
100
];
getAddrInfoErrorString
(
rc
,
errBuf
,
sizeof
(
errBuf
));
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"getaddrinfo() failed: "
<<
errBuf
;
throw
ex
;
}
}
struct
sockaddr_in
s_in
;
if
(
AF_INET
!=
res
->
ai_family
or
SOCK_STREAM
!=
res
->
ai_socktype
or
sizeof
(
s_in
)
!=
res
->
ai_addrlen
)
{
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"getaddrinfo() bad result: either ai_family or ai_socktype or ai_addrlen are wrong"
;
freeaddrinfo
(
res
);
throw
ex
;
}
memcpy
(
&
s_in
,
res
->
ai_addr
,
sizeof
(
s_in
));
int
protocol
=
res
->
ai_protocol
;
socklen_t
length
=
res
->
ai_addrlen
;
freeaddrinfo
(
res
);
struct
addrinfo
*
res
=
NULL
;
int
rc
=
getaddrinfo
(
hostName
.
c_str
(),
portStream
.
str
().
c_str
(),
&
hints
,
&
res
);
// If getaddrinfo() returned a negative value
if
(
0
!=
rc
)
{
char
errBuf
[
100
];
getAddrInfoErrorString
(
rc
,
errBuf
,
sizeof
(
errBuf
));
return
connectWithTimeout
(
AF_INET
,
SOCK_STREAM
,
protocol
,
(
struct
sockaddr
*
)(
&
s_in
),
length
,
timeout
);
}
catch
(
castor
::
exception
::
Exception
&
ce
)
{
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"getaddrinfo() failed: "
<<
errBuf
;
ex
.
getMessage
()
<<
ce
.
getMessage
().
str
()
<<
": hostName="
<<
hostName
<<
", port="
<<
port
<<
", timeout="
<<
timeout
;
throw
ex
;
}
struct
sockaddr_in
s_in
;
if
(
AF_INET
!=
res
->
ai_family
or
SOCK_STREAM
!=
res
->
ai_socktype
or
sizeof
(
s_in
)
!=
res
->
ai_addrlen
)
{
}
catch
(
std
::
exception
&
se
)
{
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"getaddrinfo() bad result: either ai_family or ai_socktype or ai_addrlen are wrong"
;
freeaddrinfo
(
res
);
ex
.
getMessage
()
<<
se
.
what
()
<<
": hostName="
<<
hostName
<<
", port="
<<
port
<<
", timeout="
<<
timeout
;
throw
ex
;
}
catch
(...)
{
castor
::
exception
::
Exception
ex
;
ex
.
getMessage
()
<<
"Failed to connect: Caught an unknown exception"
<<
": hostName="
<<
hostName
<<
", port="
<<
port
<<
", timeout="
<<
timeout
;
throw
ex
;
}
memcpy
(
&
s_in
,
res
->
ai_addr
,
sizeof
(
s_in
));
int
protocol
=
res
->
ai_protocol
;
socklen_t
length
=
res
->
ai_addrlen
;
freeaddrinfo
(
res
);
rc
=
connectWithTimeout
(
AF_INET
,
SOCK_STREAM
,
protocol
,
(
struct
sockaddr
*
)(
&
s_in
),
length
,
timeout
);
return
rc
;
}
//------------------------------------------------------------------------------
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment