Skip to content

Commit

Permalink
Added Jython support.
Browse files Browse the repository at this point in the history
  • Loading branch information
eandersson committed Feb 15, 2014
1 parent f73c141 commit 256ed3d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pika/adapters/base_connection.py
Expand Up @@ -11,6 +11,11 @@
from pika import connection
from pika import exceptions

try:
SOL_TCP = socket.SOL_TCP
except AttributeError:
SOL_TCP = 6

LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -155,7 +160,7 @@ def _check_state_on_disconnect(self):
def _create_and_connect_to_socket(self, sock_addr_tuple):
"""Create socket and connect to it, using SSL if enabled."""
self.socket = socket.socket(sock_addr_tuple[0], socket.SOCK_STREAM, 0)
self.socket.setsockopt(socket.SOL_TCP, socket.TCP_NODELAY, 1)
self.socket.setsockopt(SOL_TCP, socket.TCP_NODELAY, 1)
self.socket.settimeout(self.params.socket_timeout)

# Wrap socket if using SSL
Expand Down
12 changes: 9 additions & 3 deletions pika/adapters/blocking_connection.py
Expand Up @@ -10,6 +10,7 @@
classes.
"""
import os
import logging
import select
import socket
Expand All @@ -26,6 +27,11 @@
from pika import utils
from pika.adapters import base_connection

if os.name == 'java':
from select import cpython_compatible_select as select_function
else:
from select import select as select_function

LOGGER = logging.getLogger(__name__)


Expand Down Expand Up @@ -60,7 +66,7 @@ def __init__(self, fd, poll_timeout=POLL_TIMEOUT):
"""
self.fd = fd
self.poll_timeout = poll_timeout
if hasattr(select, 'poll'):
if hasattr(select, 'poll') and os.name != 'java':
self.poller = select.poll()
self.poll_events = select.POLLIN | select.POLLPRI
self.poller.register(self.fd, self.poll_events)
Expand All @@ -79,8 +85,8 @@ def ready(self):
events = self.poller.poll(self.poll_timeout)
return bool(events)
else:
ready, unused_wri, unused_err = select.select([self.fd], [], [],
self.poll_timeout)
ready, unused_wri, unused_err = select_function([self.fd], [], [],
self.poll_timeout)
return bool(ready)


Expand Down

3 comments on commit 256ed3d

@duylong
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,

I have a error during the connection with SSL port :

__init__() got an unexpected keyword argument 'do_handshake_on_connect'

Best regards,

@eandersson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey,

I'll take a look sometime this week.

[Edit] Hmm. This should be supported according to the documentation. I'll have to run some tests, what version of Jython are you running?

@eandersson
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce this, but this should be supported. It is most likely a bug in 2.7b1. I could easily write a patch for this, but it sounds like it would be better to report it as a Jython bug on their site.

This is at the very least supported in 2.5.2 -- http://www.jython.org/docs/library/ssl.html#ssl.wrap_socket

Please sign in to comment.