forked from quintagroup/udt_py
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
beano
committed
Jan 30, 2011
0 parents
commit a7b0e36
Showing
8 changed files
with
917 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
Copyright (c) 2011, Pykara Ltd | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
* Redistributions of source code must retain the above copyright notice, | ||
this list of conditions and the following disclaimer. | ||
|
||
* Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
* Neither the name of the Pykara Ltd nor the names of its contributors may | ||
be used to endorse or promote products derived from this software without | ||
specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | ||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | ||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
from distutils.core import setup, Extension | ||
|
||
from os.path import join | ||
|
||
module = Extension( | ||
'_udt', | ||
sources = ['udt_py.cxx'], | ||
include_dirs = [".", "../udt4/src"], | ||
libraries = ['udt'], | ||
library_dirs = ['../udt4/src'], | ||
extra_link_args = ['-Wl,-R../udt4/src/'], | ||
) | ||
|
||
setup ( | ||
name = 'udt_py', | ||
version = '1.0', | ||
description = 'Python bindings for UDT', | ||
ext_modules = [module] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/python | ||
|
||
import udt | ||
import socket | ||
import time | ||
|
||
s = udt.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) | ||
s.connect(("localhost", 5555)) | ||
while(1): | ||
buf = s.recvmsg(1024) | ||
print `buf` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/python | ||
|
||
import udt | ||
import socket | ||
import time | ||
|
||
s = udt.socket(socket.AF_INET, socket.SOCK_DGRAM, 0) | ||
s.bind(("127.0.0.1", 5555)) | ||
s.listen(10) | ||
while 1: | ||
client = s.accept() | ||
for i in range(100): | ||
print client.perfmon(1) | ||
client.sendmsg("Hello World" * 10, -1, 0) | ||
client.close() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/python | ||
|
||
import unittest | ||
import udt | ||
import _udt | ||
import socket | ||
|
||
class TestSocket(unittest.TestCase): | ||
def create_socket(self): | ||
return udt.socket(socket.AF_INET, socket.SOCK_STREAM, 0) | ||
|
||
def create_int_socket(self): | ||
return _udt.socket(socket.AF_INET, socket.SOCK_STREAM, 0) | ||
|
||
def test_init(self): | ||
s = self.create_socket() | ||
self.assertEquals(s.family, socket.AF_INET) | ||
self.assertEquals(s.type, socket.SOCK_STREAM) | ||
self.assertEquals(s.proto, 0) | ||
|
||
def test_not_enough_args_init(self): | ||
self.assertRaises(TypeError, udt.socket, ()) | ||
|
||
def test_close(self): | ||
s = self.create_socket() | ||
# perhaps this should fail since it was never open? | ||
s.close() | ||
|
||
def test_double_close(self): | ||
s = self.create_socket() | ||
s.close() | ||
self.assertRaises(RuntimeError, s.close, ()) | ||
|
||
def test_connect_bad_args(self): | ||
addr = ("192.168.0.1", 2222) | ||
s = self.create_int_socket() | ||
# 0 args | ||
self.assertRaises(TypeError, s.connect, ()) | ||
# 1 arg | ||
self.assertRaises(TypeError, s.connect, "localhost", 22, ) | ||
# string port | ||
self.assertRaises(TypeError, s.connect, ("localhost", "22")) | ||
|
||
def test_connect_no_listen(self): | ||
s = self.create_socket() | ||
self.assertRaises(RuntimeError, s.connect, ("127.0.0.1", 2344)) | ||
self.assertRaises(RuntimeError, s.connect, ("localhost", 2344)) | ||
|
||
def test_bind_ok(self): | ||
s = self.create_socket() | ||
s.bind(("127.0.0.1", 3333)) | ||
|
||
def test_startup(self): | ||
udt.startup() | ||
|
||
def test_cleanup(self): | ||
udt.cleanup() | ||
|
||
unittest.main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/python | ||
|
||
# use socket library for portability | ||
import socket as socketlib | ||
from _udt import * | ||
import _udt | ||
|
||
class socket(_udt.socket): | ||
def connect(self, addr): | ||
conn_addr = self._get_addr(addr) | ||
return _udt.socket.connect(self, conn_addr) | ||
|
||
def bind(self, addr): | ||
bind_addr = self._get_addr(addr) | ||
return _udt.socket.bind(self, bind_addr) | ||
|
||
def _get_addr(self, (host, port)): | ||
family, socktype, proto, name, addr = socketlib.getaddrinfo( | ||
host, | ||
port, | ||
self.family, | ||
0, | ||
self.proto, | ||
0 | ||
)[0] | ||
return addr |
Oops, something went wrong.