Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: use send, not sendto on connected socket #87

Merged
merged 1 commit into from
Jul 3, 2014
Merged

test: use send, not sendto on connected socket #87

merged 1 commit into from
Jul 3, 2014

Conversation

larsbutler
Copy link
Member

Fixes #86.

According to the Python docs
(https://docs.python.org/2/library/socket.html#socket.socket.sendto),
you should not use socket.sendto if a socket is already connected.

Linux (Ubuntu 12.04) seems to be forgiving of this behavior, but when I
run tests on OSX, I get several socket.error: [Errno 56] Socket is already connected errors in the test suite.

This behavior can be demonstrated with the following Python script:

import socket

receiver = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

addr = ('127.0.0.1', 27000)
receiver.bind(addr)
sender.connect(addr)

num_bytes = sender.send(b'foo')
print('Received: %s' % receiver.recv(num_bytes))

num_bytes = sender.sendto(b'bar', addr)
print('Received: %s' % receiver.recv(num_bytes))

On Linux, this works and the received messages are printed.
On OSX, the sendto calls raises a Socket is already connected error.

According to the Python docs
(https://docs.python.org/2/library/socket.html#socket.socket.sendto),
you should not use `socket.sendto` if a socket is already connected.

Linux (Ubuntu 12.04) seems to be forgiving of this behavior, but when I
run tests on OSX, I get several `socket.error: [Errno 56] Socket is
already connected` errors in the test suite.

This behavior can be demonstrated with the following Python script:

---
import socket

receiver = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sender = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

addr = ('127.0.0.1', 27000)
receiver.bind(addr)
sender.connect(addr)

num_bytes = sender.send(b'foo')
print('Received: %s' % receiver.recv(num_bytes))

num_bytes = sender.sendto(b'bar', addr)
print('Received: %s' % receiver.recv(num_bytes))
---

On Linux, this works and the received messages are printed.
On OSX, the `sendto` calls raises a `Socket is already connected` error.
pkit added a commit that referenced this pull request Jul 3, 2014
test: use `send`, not `sendto` on connected socket
@pkit pkit merged commit de07aaa into zerovm:icehouse Jul 3, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants