Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
64d4a8fc
Commit
64d4a8fc
authored
Jun 11, 2010
by
Denis Bilenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
socket: add source_address argument to create_connection
parent
6ac55725
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
2 deletions
+6
-2
gevent/socket.py
gevent/socket.py
+6
-2
No files found.
gevent/socket.py
View file @
64d4a8fc
...
@@ -553,7 +553,7 @@ try:
...
@@ -553,7 +553,7 @@ try:
except
AttributeError
:
except
AttributeError
:
_GLOBAL_DEFAULT_TIMEOUT
=
object
()
_GLOBAL_DEFAULT_TIMEOUT
=
object
()
def
create_connection
(
address
,
timeout
=
_GLOBAL_DEFAULT_TIMEOUT
):
def
create_connection
(
address
,
timeout
=
_GLOBAL_DEFAULT_TIMEOUT
,
source_address
=
None
):
"""Connect to *address* and return the socket object.
"""Connect to *address* and return the socket object.
Convenience function. Connect to *address* (a 2-tuple ``(host,
Convenience function. Connect to *address* (a 2-tuple ``(host,
...
@@ -561,7 +561,9 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
...
@@ -561,7 +561,9 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
*timeout* parameter will set the timeout on the socket instance
*timeout* parameter will set the timeout on the socket instance
before attempting to connect. If no *timeout* is supplied, the
before attempting to connect. If no *timeout* is supplied, the
global default timeout setting returned by :func:`getdefaulttimeout`
global default timeout setting returned by :func:`getdefaulttimeout`
is used.
is used. If *source_address* is set it must be a tuple of (host, port)
for the socket to bind as a source address before making the connection.
An host of '' or port 0 tells the OS to use the default.
"""
"""
msg
=
"getaddrinfo returns an empty list"
msg
=
"getaddrinfo returns an empty list"
...
@@ -573,6 +575,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
...
@@ -573,6 +575,8 @@ def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT):
sock
=
socket
(
af
,
socktype
,
proto
)
sock
=
socket
(
af
,
socktype
,
proto
)
if
timeout
is
not
_GLOBAL_DEFAULT_TIMEOUT
:
if
timeout
is
not
_GLOBAL_DEFAULT_TIMEOUT
:
sock
.
settimeout
(
timeout
)
sock
.
settimeout
(
timeout
)
if
source_address
:
sock
.
bind
(
source_address
)
sock
.
connect
(
sa
)
sock
.
connect
(
sa
)
return
sock
return
sock
except
error
,
msg
:
except
error
,
msg
:
...
...
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