Skip to content

Commit

Permalink
Merge pull request #32 from SmithSamuelM/master
Browse files Browse the repository at this point in the history
Fixed connection limit in tcp server upped listen backlog to 128 from 5 default
  • Loading branch information
SmithSamuelM authored Dec 22, 2023
2 parents 8e655fb + db3c09f commit eb69cf4
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 42 deletions.
19 changes: 8 additions & 11 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

setup(
name='hio',
version='0.6.9', # also change in src/hio/__init__.py
version='0.6.10', # also change in src/hio/__init__.py
license='Apache Software License 2.0',
description='Hierarchical Concurrency with Async IO',
long_description=("HIO Hierarchical Concurrency and Asynchronous IO Library. "
Expand Down Expand Up @@ -81,14 +81,11 @@
],
python_requires='>=3.10.4',
install_requires=[
'netifaces>=0.11.0',
'lmdb>=1.3.0',
'pysodium>=0.7.12',
'blake3>=0.3.1',
'msgpack>=1.0.4',
'cbor2>=5.4.3',
'multidict>=6.0.2',
'falcon>=3.1.0',
'lmdb>=1.4.1',
'msgpack>=1.0.7',
'cbor2>=5.5.1',
'multidict>=6.0.4',
'falcon>=3.1.3',
'ordered-set>=4.1.0',

],
Expand All @@ -98,8 +95,8 @@
# ':python_version=="2.6"': ['argparse'],
},
tests_require=[
'coverage>=6.5.0',
'pytest>=7.2.0',
'coverage>=7.3.4',
'pytest>=7.4.3',
],
setup_requires=[
],
Expand Down
2 changes: 1 addition & 1 deletion src/hio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
hio package
"""

__version__ = '0.6.9' # also change in setup.py
__version__ = '0.6.10' # also change in setup.py

from .hioing import Mixin, HioError, ValidationError, VersionError
43 changes: 22 additions & 21 deletions src/hio/core/coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import subprocess
import socket

import netifaces
#import netifaces # netifaces2

from ..hioing import ValidationError

Expand Down Expand Up @@ -42,26 +42,27 @@ def normalizeHost(host):
host = info[0][4][0]
return host


def getDefaultHost():
"""
Returns host ip address of default interface using netifaces
"""
iface = netifaces.gateways()['default'][netifaces.AF_INET][1]
info = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]
host = info['addr']
return host


def getDefaultBroadcast():
"""
Returns broadcast ip address of default interface using netifaces
"""
iface = netifaces.gateways()['default'][netifaces.AF_INET][1]
info = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]
bcast = info['broadcast']
return bcast
# netifaces not fully supported on macos anymore only linux
#def getDefaultHost():
#"""
#Returns host ip address of default interface using netifaces
#"""
##iface = netifaces.gateways()['default'][netifaces.AF_INET][1]
#iface = netifaces.default_gateway(old_api=True)[netifaces.AF_INET][1]
#info = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]
#host = info['addr']
#return host


#def getDefaultBroadcast():
#"""
#Returns broadcast ip address of default interface using netifaces

#"""
#iface = netifaces.gateways()['default'][netifaces.AF_INET][1]
#info = netifaces.ifaddresses(iface)[netifaces.AF_INET][0]
#bcast = info['broadcast']
#return bcast


def arpCreate(ether, host, interface="en0", temp=True):
Expand Down
6 changes: 4 additions & 2 deletions src/hio/core/tcp/serving.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ class Acceptor(tyming.Tymee):
.opened is boolean, True if listen socket .ss opened. False otherwise
"""

def __init__(self, ha=None, bs=8096, **kwa):
def __init__(self, ha=None, bs=8096, bl=128, **kwa):
"""
Initialization method for instance.
ha is host address duple (host, port) listen interfaces
host = "" or "0.0.0.0" means listen on all interfaces
bs = buffer size
bl (int): backlog size of not yet accepted concurrent tcp connections
"""
super(Acceptor, self).__init__(**kwa)
Expand All @@ -96,6 +97,7 @@ def __init__(self, ha=None, bs=8096, **kwa):
host = "::1" # need specific interface for tls
self.eha = (host, port)
self.bs = bs
self.bl = bl
self.ss = None # listen socket for accepts
self.axes = deque() # deque of duple (ca, cs) accepted connections
self.opened = False
Expand Down Expand Up @@ -141,7 +143,7 @@ def open(self):

try: # bind to listen socket (host, port) to receive connections
self.ss.bind(self.ha)
self.ss.listen(5)
self.ss.listen(self.bl) # this determines number of concurrent connections
except OSError as ex:
self.close()
logger.error("Error binding server listen socket.\n%s\n", ex)
Expand Down
3 changes: 2 additions & 1 deletion tests/core/http/falcon/test_falcon.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,8 @@ def test_get_static_sink():
# get trial.js
rep = client.simulate_get('/static/index.js')
assert rep.status == falcon.HTTP_OK
assert rep.headers['content-type'] == 'application/javascript; charset=UTF-8'
assert (rep.headers['content-type'] == 'application/javascript; charset=UTF-8' or
rep.headers['content-type'] == 'text/javascript; charset=UTF-8')
assert len(rep.text) > 0
assert rep.text == '// vanilla index.js\n\nm.render(document.body, "Hello world")\n'

Expand Down
12 changes: 6 additions & 6 deletions tests/core/test_coring.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

import pytest

from hio.core.coring import (normalizeHost, getDefaultHost, getDefaultBroadcast,
arpCreate, arpDelete)
from hio.core.coring import (normalizeHost, arpCreate, arpDelete)

def test_ip_utils():
"""
Expand All @@ -16,11 +15,12 @@ def test_ip_utils():
host = normalizeHost("localhost")
assert host == "127.0.0.1"

host = getDefaultHost()
assert host != ""
# netifaces not fully supported on macos only linux now
#host = getDefaultHost()
#assert host != ""

bcast = getDefaultBroadcast()
assert bcast.endswith(".255") or bcast.endswith(".127") or bcast.endswith(".63")
#bcast = getDefaultBroadcast()
#assert bcast.endswith(".255") or bcast.endswith(".127") or bcast.endswith(".63")

"""Done Test"""

Expand Down

0 comments on commit eb69cf4

Please sign in to comment.