├── .gitignore ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── aws ├── ec2-prep.bash └── python │ ├── .gitignore │ ├── LICENSE │ ├── MANIFEST.in │ ├── PUBLISH_STEPS │ ├── README │ ├── README.md │ ├── build.bash │ ├── clean.bash │ ├── publish_layer.py │ ├── python_packages │ ├── README.md │ ├── lambda_networking │ │ ├── __init__.py │ │ └── connect.py │ └── setup.py │ ├── setup.py │ ├── src │ └── udt4py.pyx │ └── tests │ ├── lambda │ ├── LICENSE.TXT │ ├── README │ ├── build.bash │ ├── sar-publish.bash │ ├── src │ │ ├── bandwidth.py │ │ ├── networking_sample.py │ │ └── requirements.txt │ └── template.yaml │ ├── speed.py │ ├── udt_epoll.py │ └── udt_socket.py ├── docs ├── CNAME ├── FAQ.md ├── _config.yml ├── getting_started.md ├── index.md └── overview.md └── udt └── udt4 ├── LICENSE.txt ├── Makefile ├── README.txt ├── RELEASE_NOTES.txt ├── app ├── Makefile ├── appclient.cpp ├── appserver.cpp ├── cc.h ├── recvfile.cpp ├── sendfile.cpp ├── test.cpp └── test_util.h ├── doc ├── doc │ ├── accept.htm │ ├── bind.htm │ ├── ccc.htm │ ├── cleanup.htm │ ├── close.htm │ ├── connect.htm │ ├── copy.htm │ ├── ecode.htm │ ├── epoll.htm │ ├── error.htm │ ├── footer.htm │ ├── function.htm │ ├── header.htm │ ├── intro.htm │ ├── listen.htm │ ├── make.htm │ ├── opt.htm │ ├── peername.htm │ ├── recv.htm │ ├── recvfile.htm │ ├── recvmsg.htm │ ├── reference.htm │ ├── select.htm │ ├── selectex.htm │ ├── send.htm │ ├── sendfile.htm │ ├── sendmsg.htm │ ├── socket.htm │ ├── sockname.htm │ ├── startup.htm │ ├── structure.htm │ ├── t-cc.htm │ ├── t-config.htm │ ├── t-data.htm │ ├── t-error.htm │ ├── t-file.htm │ ├── t-firewall.htm │ ├── t-hello.htm │ ├── t-intro.htm │ ├── t-msg.htm │ ├── t-udt3.htm │ ├── trace.htm │ ├── treeview.css │ ├── tutorial.htm │ └── udtdoc.css ├── hlp │ ├── ix_book.gif │ ├── ix_down.gif │ ├── ix_end.gif │ ├── ix_endm.gif │ ├── ix_endp.gif │ ├── ix_leaf.gif │ ├── ix_line.gif │ ├── ix_link.gif │ ├── ix_list.gif │ ├── ix_listm.gif │ ├── ix_listp.gif │ ├── ix_open.gif │ ├── ix_space.gif │ └── ix_up.gif ├── index.htm └── main.htm ├── draft-gg-udt-xx.txt ├── src ├── Makefile ├── api.cpp ├── api.h ├── buffer.cpp ├── buffer.h ├── cache.cpp ├── cache.h ├── ccc.cpp ├── ccc.h ├── channel.cpp ├── channel.h ├── common.cpp ├── common.h ├── core.cpp ├── core.h ├── epoll.cpp ├── epoll.h ├── list.cpp ├── list.h ├── md5.cpp ├── md5.h ├── packet.cpp ├── packet.h ├── queue.cpp ├── queue.h ├── udt.h ├── window.cpp └── window.h └── win ├── appclient.vcproj ├── appserver.vcproj ├── recvfile.vcproj ├── sendfile.vcproj ├── test.vcproj ├── udt.sln └── udt.vcproj /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | layer_staging/ 3 | udt/udt4/src/udt 4 | udt/udt4/app/ 5 | jnk 6 | 7 | # Ignore generated YAML files that are part of the SAM workflow process 8 | output.yaml 9 | 10 | # Byte-compiled / optimized / DLL files 11 | __pycache__/ 12 | *.py[cod] 13 | *$py.class 14 | 15 | # C extensions 16 | *.so 17 | *.o 18 | *.a 19 | 20 | # Distribution / packaging 21 | .Python 22 | build/ 23 | develop-eggs/ 24 | dist/ 25 | downloads/ 26 | eggs/ 27 | .eggs/ 28 | lib/ 29 | lib64/ 30 | parts/ 31 | sdist/ 32 | var/ 33 | wheels/ 34 | *.egg-info/ 35 | .installed.cfg 36 | *.egg 37 | MANIFEST 38 | 39 | # PyInstaller 40 | # Usually these files are written by a python script from a template 41 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 42 | *.manifest 43 | *.spec 44 | 45 | # Installer logs 46 | pip-log.txt 47 | pip-delete-this-directory.txt 48 | 49 | # Unit test / coverage reports 50 | htmlcov/ 51 | .tox/ 52 | .coverage 53 | .coverage.* 54 | .cache 55 | nosetests.xml 56 | coverage.xml 57 | *.cover 58 | .hypothesis/ 59 | .pytest_cache/ 60 | 61 | # Translations 62 | *.mo 63 | *.pot 64 | 65 | # Django stuff: 66 | *.log 67 | local_settings.py 68 | db.sqlite3 69 | 70 | # Flask stuff: 71 | instance/ 72 | .webassets-cache 73 | 74 | # Scrapy stuff: 75 | .scrapy 76 | 77 | # Sphinx documentation 78 | docs/_build/ 79 | 80 | # PyBuilder 81 | target/ 82 | 83 | # Jupyter Notebook 84 | .ipynb_checkpoints 85 | 86 | # pyenv 87 | .python-version 88 | 89 | # celery beat schedule file 90 | celerybeat-schedule 91 | 92 | # SageMath parsed files 93 | *.sage.py 94 | 95 | # Environments 96 | .env 97 | .venv 98 | env/ 99 | venv/ 100 | ENV/ 101 | env.bak/ 102 | venv.bak/ 103 | 104 | # Spyder project settings 105 | .spyderproject 106 | .spyproject 107 | 108 | # Rope project settings 109 | .ropeproject 110 | 111 | # mkdocs documentation 112 | /site 113 | 114 | # mypy 115 | .mypy_cache/ 116 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Racially insensitive terminology in documentation or software 32 | * Other conduct which could reasonably be considered inappropriate in a 33 | professional setting 34 | 35 | ## Our Responsibilities 36 | 37 | Project maintainers are responsible for clarifying the standards of acceptable 38 | behavior and are expected to take appropriate and fair corrective action in 39 | response to any instances of unacceptable behavior. 40 | 41 | Project maintainers have the right and responsibility to remove, edit, or 42 | reject comments, commits, code, wiki edits, issues, and other contributions 43 | that are not aligned to this Code of Conduct, or to ban temporarily or 44 | permanently any contributor for other behaviors that they deem inappropriate, 45 | threatening, offensive, or harmful. 46 | 47 | ## Scope 48 | 49 | This Code of Conduct applies both within project spaces and in public spaces 50 | when an individual is representing the project or its community. Examples of 51 | representing a project or community include using an official project e-mail 52 | address, posting via an official social media account, or acting as an appointed 53 | representative at an online or offline event. Representation of a project may be 54 | further defined and clarified by project maintainers. 55 | 56 | ## Enforcement 57 | 58 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 59 | reported by contacting the project team at timawagner@gmail.com. All 60 | complaints will be reviewed and investigated and will result in a response that 61 | is deemed necessary and appropriate to the circumstances. The project team is 62 | obligated to maintain confidentiality with regard to the reporter of an incident. 63 | Further details of specific enforcement policies may be posted separately. 64 | 65 | Project maintainers who do not follow or enforce the Code of Conduct in good 66 | faith may face temporary or permanent repercussions as determined by other 67 | members of the project's leadership. 68 | 69 | ## Attribution 70 | 71 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 72 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 73 | 74 | [homepage]: https://www.contributor-covenant.org 75 | 76 | For answers to common questions about this code of conduct, see 77 | https://www.contributor-covenant.org/faq 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Additional code and derivative works created by the Serverless Networking project are licensed as follows: 2 | BSD 2-Clause License 3 | 4 | Copyright (c) 2019, Serverless Tech, Inc. 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are met: 9 | 10 | 1. Redistributions of source code must retain the above copyright notice, this 11 | list of conditions and the following disclaimer. 12 | 13 | 2. Redistributions in binary form must reproduce the above copyright notice, 14 | this list of conditions and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | udt4py License: 29 | Copyright (c) 2014, Samsung Electronics Co.,Ltd. 30 | All rights reserved. 31 | 32 | Redistribution and use in source and binary forms, with or without 33 | modification, are permitted provided that the following conditions are met: 34 | 35 | 1. Redistributions of source code must retain the above copyright notice, this 36 | list of conditions and the following disclaimer. 37 | 2. Redistributions in binary form must reproduce the above copyright notice, 38 | this list of conditions and the following disclaimer in the documentation 39 | and/or other materials provided with the distribution. 40 | 41 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 42 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 43 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 44 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 45 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 46 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 47 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 48 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 49 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 50 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 51 | 52 | The views and conclusions contained in the software and documentation are those 53 | of the authors and should not be interpreted as representing official policies, 54 | either expressed or implied, of Samsung Electronics Co.,Ltd. 55 | 56 | UDT License: 57 | Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 58 | All rights reserved. 59 | 60 | Redistribution and use in source and binary forms, with or without 61 | modification, are permitted provided that the following conditions are 62 | met: 63 | 64 | * Redistributions of source code must retain the above 65 | copyright notice, this list of conditions and the 66 | following disclaimer. 67 | 68 | * Redistributions in binary form must reproduce the 69 | above copyright notice, this list of conditions 70 | and the following disclaimer in the documentation 71 | and/or other materials provided with the distribution. 72 | 73 | * Neither the name of the University of Illinois 74 | nor the names of its contributors may be used to 75 | endorse or promote products derived from this 76 | software without specific prior written permission. 77 | 78 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 79 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 80 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 81 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 82 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 83 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 84 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 85 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 86 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 87 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 88 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 89 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ServerlessNetworkingClients 2 | Client SDKs for ServerlessNetworking. 3 | User documentation can be found at https://networkingclients.serverlesstech.net/ 4 | -------------------------------------------------------------------------------- /aws/ec2-prep.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Commands needed to turn a vanilla EC2 Amazon Linux 2 machine into 3 | # one that's ready to build & use udt, udt4py, and aws commands. 4 | sudo yum install python37 5 | sudo yum install gcc 6 | sudo yum install gcc-c++ 7 | sudo yum install git 8 | sudo yum install python3-devel 9 | 10 | -------------------------------------------------------------------------------- /aws/python/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_STORE 2 | .vscode/ 3 | 4 | stage_layer/ 5 | 6 | *.py[cod] 7 | *.cpp 8 | 9 | # C extensions 10 | *.so 11 | *.o 12 | 13 | # Packages 14 | *.egg 15 | *.egg-info 16 | dist 17 | build 18 | eggs 19 | parts 20 | bin 21 | var 22 | sdist 23 | develop-eggs 24 | .installed.cfg 25 | lib 26 | lib64 27 | __pycache__ 28 | build 29 | 30 | # Installer logs 31 | pip-log.txt 32 | 33 | # Unit test / coverage reports 34 | .coverage 35 | .tox 36 | nosetests.xml 37 | 38 | # Translations 39 | *.mo 40 | 41 | # Mr Developer 42 | .mr.developer.cfg 43 | .project 44 | .pydevproject 45 | -------------------------------------------------------------------------------- /aws/python/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014, Samsung Electronics Co.,Ltd. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 17 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 18 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 19 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 20 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 22 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | 24 | The views and conclusions contained in the software and documentation are those 25 | of the authors and should not be interpreted as representing official policies, 26 | either expressed or implied, of Samsung Electronics Co.,Ltd.. 27 | -------------------------------------------------------------------------------- /aws/python/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include udt4py/udt4py.pyx 2 | exclude udt4py/udt4py.cpp 3 | include tests/*.py 4 | include LICENSE 5 | include README 6 | include README.md 7 | include setup.py 8 | -------------------------------------------------------------------------------- /aws/python/PUBLISH_STEPS: -------------------------------------------------------------------------------- 1 | . venv/bin/activate 2 | # If from a clean install... 3 | pip install boto3 4 | python publish_layer.py 5 | -------------------------------------------------------------------------------- /aws/python/README: -------------------------------------------------------------------------------- 1 | README.md -------------------------------------------------------------------------------- /aws/python/README.md: -------------------------------------------------------------------------------- 1 | udt4py 2 | ====== 3 | 4 | libudt4 Python wrapper written with Cython. 5 | 6 | Tested with Python 2.7 and Python 3.3 on Linux. In buffer operations bytes, 7 | bytearray and memoryview objects are supported, allowing zero-copy operations. 8 | 9 | In order to build the native module, execute: 10 | 11 | ```bash 12 | python3 setup.py build_ext --inplace 13 | ``` 14 | 15 | In Ubuntu, you will need ``cython3`` package. 16 | To run the tests, execute: 17 | 18 | ```bash 19 | PYTHONPATH=`pwd` nosetests3 -w tests --tests udt_socket,udt_epoll 20 | ``` 21 | 22 | Example usage: 23 | 24 | ```python 25 | from udt4py import UDTSocket 26 | 27 | 28 | if __name__ == "__main__": 29 | socket = UDTSocket() 30 | socket.bind("0.0.0.0:7777") 31 | socket.listen() 32 | channel = socket.accept() 33 | msg = bytearray(5) 34 | channel.recv(msg) 35 | ``` 36 | 37 | Released under Simplified BSD License. 38 | Copyright (c) 2014, Samsung Electronics Co.,Ltd. 39 | -------------------------------------------------------------------------------- /aws/python/build.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Build udt4py. This script can only be run from the .../aws/python directory and must 3 | # be executed either on an EC2 Amazon Linux2 instance or in a Docker container emulating 4 | # the Lambda environment in order for it to be runtime binary compatible with Lambda execution. 5 | # Make sure the the ec2-prep command has been run before attempting this from EC2! 6 | # 7 | # To prepare to run this script, see ../ec2-prep.bash 8 | # To package the result of running this script, see ./package.py 9 | # To clean up the artifacts from this script, see ./clean.bash 10 | 11 | # Ensure that udt4 itself has been built 12 | echo "Ensuring udt4 C++ library is built" 13 | pushd ../../udt/udt4 14 | make 15 | popd 16 | 17 | # Create a Python virtual environment 18 | echo "Setting up Python 3 virtual environment and staging ground" 19 | rm -rf venv 20 | mkdir venv 21 | python3 -m venv venv 22 | . venv/bin/activate 23 | 24 | # Ensure websockets installed; we'll add this to the layer 25 | pip install --upgrade pip 26 | pip install websockets 27 | pip install boto3 28 | 29 | # Cython build requires the C/C++ udt4 includes in order to compile 30 | echo "Compiling and packaging udt4py" 31 | export LD_LIBRARY_PATH=../../udt/udt4/src 32 | python setup.py build_ext --inplace 33 | 34 | # Package lambda_networking 35 | echo "Packaging lambda_networking" 36 | pushd python_packages 37 | python setup.py sdist bdist 38 | popd 39 | echo "Installing lambda_networking" 40 | pip install python_packages/ 41 | 42 | # Minimal test to ensure build, install, and LD_LIBRARY_PATH all work 43 | echo "Verifying lambda_networking package and built libraries all load" 44 | export LD_LIBRARY_PATH=../../udt/udt4/src 45 | python python_packages/lambda_networking/connect.py 46 | 47 | # Stage for publishing but don't actually publish in this script 48 | echo "Staging layer (see publish script for actual publishing commands)" 49 | rm -rf stage_layer 50 | export DIR=stage_layer/python/lib/python3.7/site-packages 51 | mkdir stage_layer && mkdir stage_layer/lib && mkdir stage_layer/python && mkdir stage_layer/python/lib && mkdir stage_layer/python/lib/python3.7 && mkdir $DIR 52 | # Package UDT C++ networking library 53 | cp ../../udt/udt4/src/libudt.so stage_layer/lib 54 | # Package udt4py Python wrapper 55 | cp udt4py.cpython-37m-x86_64-linux-gnu.so $DIR 56 | # Package the required Python dependencies (websockets, e.g.) 57 | # Remove C files and all pyc's in the __pycache__; they're not needed for layer execution. 58 | cp -r venv/lib/python3.7/site-packages/websockets $DIR 59 | rm -rf $DIR/websockets/__pycache__ 60 | rm -f $DIR/websockets/*.c 61 | rm -rf $DIR/websockets/extensions/__pycache__ 62 | cp -r venv/lib/python3.7/site-packages/lambda_networking $DIR 63 | rm -rf $DIR/lambda_networking/__pycache__ 64 | cd stage_layer && zip -r layer.zip lib python 65 | 66 | echo "Layer build script completed" 67 | -------------------------------------------------------------------------------- /aws/python/clean.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Clean the pyx build artifacts 3 | python setup.py clean --all 4 | rm -rf *egg* 5 | rm -f *.so 6 | rm -f src/*.cpp 7 | rm -rf stage_layer 8 | rm -rf build 9 | pushd python_packages 10 | python setup.py clean --all 11 | rm -rf *.egg-info 12 | rm -rf dist 13 | rm -rf __pycache__ 14 | rm -rf lambda_networking/__pycache__ 15 | popd 16 | 17 | -------------------------------------------------------------------------------- /aws/python/publish_layer.py: -------------------------------------------------------------------------------- 1 | import boto3 2 | import json 3 | # Globals 4 | LayerName = 'ServerlessNetworking-Python3' 5 | lambda_sdk = boto3.client('lambda') 6 | 7 | # Create a new (version of) this layer. Requires the build & package 8 | # step to have been previously performed in this directory. AWS permissions 9 | # sufficient for the two calls below must be in the ambiant environment for this to work. 10 | try: 11 | print('Initiating layer publish (this will take a few seconds)...') 12 | layer = lambda_sdk.publish_layer_version( 13 | LayerName=LayerName, 14 | Description='ServerlessNetworking AWS Lambda layer for Python3 functions', 15 | Content={ 16 | 'ZipFile': open('stage_layer/layer.zip', 'rb').read() 17 | }, 18 | CompatibleRuntimes=['python3.7'], 19 | LicenseInfo='BSD-3-Clause' 20 | ) 21 | print('Layer publishing result:') 22 | print(json.dumps(layer)) 23 | # Give the world permission to use this layer. 24 | response = lambda_sdk.add_layer_version_permission( 25 | LayerName=LayerName, 26 | VersionNumber=layer["Version"], 27 | StatementId='ServerlessNetworkingClientPublishScript', 28 | Action='lambda:GetLayerVersion', 29 | Principal='*' 30 | ) 31 | print('Layer permissioning result:') 32 | print(json.dumps(response)) 33 | except Exception as e: 34 | print('Attempt to create layer failed: ' + str(e)) 35 | -------------------------------------------------------------------------------- /aws/python/python_packages/README.md: -------------------------------------------------------------------------------- 1 | # Lambda Networking Python 3 Package 2 | 3 | To use this package see the 4 | [User and API docs](http://networkingclients.serverlesstech.net) 5 | 6 | To create issues or pull requests visit 7 | [the GitHub repo](https://github.com/serverlessunicorn/ServerlessNetworkingClients) 8 | -------------------------------------------------------------------------------- /aws/python/python_packages/lambda_networking/__init__.py: -------------------------------------------------------------------------------- 1 | # Marker file to autodetect Python package in this directory. 2 | """Lambda Networking is a Python 3 package that supports peer-to-peer networking built on top of udt4py and udt4.""" 3 | -------------------------------------------------------------------------------- /aws/python/python_packages/setup.py: -------------------------------------------------------------------------------- 1 | print('setup.py for lambda_networking package is starting...') 2 | import setuptools 3 | 4 | print('Loading README.md') 5 | with open("README.md", "r") as fh: 6 | long_description = fh.read() 7 | 8 | print('Running setup on lambda_networking package') 9 | setuptools.setup( 10 | name="lambda_networking", 11 | version="0.0.1", 12 | author="Tim Wagner", 13 | author_email="info@serverlesstech.net", 14 | description="Peer-to-peer networking for AWS Lambda", 15 | long_description=long_description, 16 | long_description_content_type="text/markdown", 17 | url="https://github.com/serverlessunicorn/ServerlessNetworkingClients", 18 | packages=setuptools.find_packages(), 19 | classifiers=[ 20 | "Programming Language :: Python :: 3", 21 | "License :: OSI Approved :: BSD License", 22 | "Operating System :: Unix", 23 | ], 24 | python_requires='>=3.7', 25 | ) 26 | print('Setup of lambda_networking package complete') 27 | 28 | -------------------------------------------------------------------------------- /aws/python/setup.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2014, Samsung Electronics Co.,Ltd. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those 26 | of the authors and should not be interpreted as representing official policies, 27 | either expressed or implied, of Samsung Electronics Co.,Ltd.. 28 | """ 29 | 30 | """ 31 | udt4py - libudt4 Cython-ish wrapper. 32 | URL: https://github.com/vmarkovtsev/udt4py 33 | Original author: Vadim Markovtsev 34 | 35 | libudt4 is (c)2001 - 2011, The Board of Trustees of the University of Illinois. 36 | libudt4 URL: http://udt.sourceforge.net/ 37 | """ 38 | 39 | from setuptools import setup,Extension 40 | setup( 41 | name="udt4py", 42 | description='libudt4 Python wrapper written with Cython', 43 | version="1.2", 44 | license="Simplified BSD", 45 | author="Samsung Electronics Co.,Ltd.", 46 | author_email="v.markovtsev@samsung.com", 47 | url="https://github.com/vmarkovtsev/udt4py", 48 | download_url='https://github.com/vmarkovtsev/udt4py', 49 | setup_requires=[ 50 | #Setuptools 18.0 properly handles Cython extensions. 51 | 'setuptools>=18.0', 52 | 'cython', 53 | ], 54 | ext_modules=[Extension('udt4py', sources=['src/udt4py.pyx'], language='c++', include_dirs=['../../udt'], libraries=['udt'])], 55 | keywords=['udt', 'udt4', 'udt4py'], 56 | classifiers=[ 57 | 'Development Status :: 4 - Beta', 58 | 'Intended Audience :: Developers', 59 | 'License :: OSI Approved :: BSD License', 60 | 'Operating System :: POSIX', 61 | 'Programming Language :: Python :: 3.7', 62 | 'Topic :: Software Development :: Libraries', 63 | 'Topic :: System :: Networking', 64 | ], 65 | ) 66 | -------------------------------------------------------------------------------- /aws/python/tests/lambda/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | BSD 2-Clause License 2 | 3 | Copyright (c) 2019, serverlessunicorn 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 17 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 | -------------------------------------------------------------------------------- /aws/python/tests/lambda/README: -------------------------------------------------------------------------------- 1 | Test configuration and rendezvous functionality for ServerlessNetworking Python3 clients in AWS Lambda. 2 | -------------------------------------------------------------------------------- /aws/python/tests/lambda/build.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Settings 4 | export GEN_TEMPLATE=output.yaml 5 | export S3_BUCKET=timsuseast1s3testbucket 6 | export STACK_NAME=pythontests 7 | 8 | # Build steps 9 | # Note that requirements.txt is empty; all requirements needed for this code 10 | # to run should come either from the Lambda python environment or the serverless networking 11 | # client layer; users should never have to install additional Python packages to use it. 12 | # (In the future, any *optional* packages should be tested separately to keep this assertion test 13 | # cleanly validated here.) 14 | touch src/requirements.txt 15 | echo "Building..." 16 | sam build 17 | echo "Packaging..." 18 | sam package --output-template $GEN_TEMPLATE --s3-bucket $S3_BUCKET 19 | echo "Deploying..." 20 | sam deploy --template-file $GEN_TEMPLATE --stack-name $STACK_NAME --capabilities CAPABILITY_NAMED_IAM 21 | echo "...SAM cloud deployment is complete; see $STACK_NAME on CloudFormation console to manage" 22 | -------------------------------------------------------------------------------- /aws/python/tests/lambda/sar-publish.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Publish a built & deployed test/example file to the Serverless Application Repository ("SAR) 4 | # You must execute ./build.bash before this command can be run. 5 | echo "sam publish invoked..." 6 | sam publish --template output.yaml --region us-east-1 7 | echo "...sam publish step complete" 8 | -------------------------------------------------------------------------------- /aws/python/tests/lambda/src/networking_sample.py: -------------------------------------------------------------------------------- 1 | # Serverless Networking: Sample code 2 | # Instructions: 3 | # (1) Run this as a python3.7 AWS Lambda function whose role permits 4 | # Lambda invocations. 5 | # (2) Ensure that the Serverless Networking Python 3 layer is attached. 6 | # (3) The function must reside in us-east-1 during the beta in order 7 | # to contact the NAT punching service endpoint. 8 | # (4) Ensure that the Lambda function has a duration >= 10 seconds to enable enough time 9 | # for spawning and connecting. 10 | 11 | import json 12 | import os 13 | from random import choice 14 | import string 15 | import time 16 | 17 | import boto3 18 | from botocore.exceptions import ClientError 19 | 20 | from udt4py import UDTSocket 21 | from lambda_networking.connect import pair 22 | 23 | lambdasdk = boto3.client('lambda') 24 | 25 | def lambda_handler(event, context): 26 | if ('invoke_type' in event): 27 | invoke_type = event['invoke_type'] 28 | else: 29 | invoke_type = 'parent' 30 | # If a pairing name is provided, use that; otherwise, generate a random one. 31 | if ('pairing_name' in event): 32 | pairing_name = event['pairing_name'] 33 | else: 34 | pairing_name = generate_pairing_name(10) 35 | print('' + invoke_type + ' using pairing_name ' + pairing_name) 36 | if (invoke_type == 'parent'): 37 | spawn_child(pairing_name) 38 | sock = pair(pairing_name) 39 | if (not sock or sock.status != UDTSocket.Status.CONNECTED): 40 | return { 41 | 'statusCode': 500, 42 | 'body': ('socket failed to rendezvous, state is:' + str(sock.status)) if sock else 'socket failed to pair' 43 | } 44 | print('networking connection established') 45 | if (invoke_type == 'parent'): 46 | # Receives block by default, so you can build simple 47 | # barrier synchronization or other choreographies, such as creating 48 | # pre-warmed Lambdas that wait to run until input is available, just 49 | # by waiting for messages. 50 | # You can also put sockets into non-blocking mode (see UDTEpoll). 51 | buf = bytearray(6) 52 | len = sock.recv(buf) 53 | msg = buf[0:len].decode('utf8') 54 | assert(msg == 'Test 1') 55 | len = sock.recv(buf) 56 | msg = buf[0:len].decode('utf8') 57 | assert(msg == 'Test 2') 58 | len = sock.recv(buf) 59 | msg = buf[0:len].decode('utf8') 60 | assert(msg == 'Test 3') 61 | 62 | with open('/tmp/foo', 'a') as file: 63 | file.write('hello at time ' + str(time.time()) + '\n') 64 | len = str(os.path.getsize('/tmp/foo')).encode('utf8') 65 | 66 | # Sockets are bidirectional: 67 | bytes_sent4 = sock.send(len) 68 | 69 | # You can also send files: 70 | sock.sendfile('/tmp/foo') 71 | else: # child 72 | # You can send data using bytes, bytearrays, and memoryviews. 73 | # Memory views guarantee zero copy transfers. 74 | bytes_sent1 = sock.send('Test 1'.encode('utf8')) 75 | bytes_sent2 = sock.send(bytes('Test 2', 'utf8')) 76 | bytes_sent3 = sock.send(memoryview(b'Test 3')) 77 | buf = bytearray(20) 78 | len = sock.recv(buf) 79 | msg = buf[0:len].decode('utf8') 80 | bytes_received = sock.recvfile('/tmp/bar', 0, int(msg)) 81 | assert(bytes_received == int(msg)) 82 | with open('/tmp/bar', 'r') as f: 83 | print(f.read()) # Check logs to verify file content 84 | # Other things you can try: 85 | # sendmsg() and recvmsg() - datagram-like transmission with TTLs 86 | # perfmon() - retrieve udt performance statistics 87 | # UDTEpoll - a select-like capability; can be used with non-blocking mode sends and receives to create 88 | # asynchronous applications 89 | sock.close() 90 | return {'statusCode': 200, 'body': 'sample completed successfully'} 91 | 92 | # Generate a random string matching the regexp [_a-zA-Z0-9]{len} 93 | def generate_pairing_name(len=10): 94 | chars = string.ascii_letters + string.digits + '_' 95 | return ''.join(choice(chars) for i in range(len)) 96 | 97 | # Launch an async "child" Lambda to act as the other side of the pair, passing 98 | # it the pairing name to use. Note that we simply use another instance of this 99 | # function for simplicity, but that's not required. 100 | def spawn_child(pairing_name): 101 | print('Beginning spawn_child for pairing name ' + pairing_name) 102 | args = { 103 | 'invoke_type': 'child', 104 | 'pairing_name': pairing_name 105 | } 106 | try: 107 | response = lambdasdk.invoke( 108 | FunctionName=os.environ['AWS_LAMBDA_FUNCTION_NAME'], 109 | InvocationType='Event', # (i.e., async) 110 | LogType='None', 111 | Payload=json.dumps(args).encode() 112 | ) 113 | except ClientError as e: 114 | print('Attempt to spawn child Lambda failed: ' + e.response['Error']['Message']) 115 | raise e 116 | -------------------------------------------------------------------------------- /aws/python/tests/lambda/src/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/aws/python/tests/lambda/src/requirements.txt -------------------------------------------------------------------------------- /aws/python/tests/lambda/template.yaml: -------------------------------------------------------------------------------- 1 | AWSTemplateFormatVersion: '2010-09-09' 2 | Transform: AWS::Serverless-2016-10-31 3 | Description: SAM file for Serverless Networking tests on Python3 4 | Globals: 5 | Function: 6 | Timeout: 3 7 | Runtime: python3.7 8 | 9 | Metadata: 10 | AWS::ServerlessRepo::Application: 11 | Name: ServerlessNetworkingPython3 12 | Description: Serverless networking client for python3.7 and forward 13 | Author: timwagner 14 | SpdxLicenseId: BSD-2-Clause 15 | #LicenseUrl: "http://udt.sourceforge.net/LICENSE.txt" 16 | LicenseUrl: LICENSE.TXT 17 | #ReadmeUrl: "https://github.com/serverlessunicorn/ServerlessNetworkingClients/blob/master/README.md" 18 | ReadmeUrl: README 19 | Labels: ['networking'] 20 | HomePageUrl: "https://github.com/serverlessunicorn/ServerlessNetworkingClients" 21 | SemanticVersion: 0.0.5 22 | SourceCodeUrl: "https://github.com/serverlessunicorn/ServerlessNetworkingClients" 23 | 24 | Resources: 25 | NetworkingSampleFunction: 26 | Type: AWS::Serverless::Function 27 | Properties: 28 | CodeUri: src/ 29 | Handler: networking_sample.lambda_handler 30 | Timeout: 10 31 | Layers: 32 | - "arn:aws:lambda:us-east-1:293602984666:layer:ServerlessNetworking-Python3:10" 33 | Policies: 34 | # TODO: This should ideally be something like !GetAtt NetworkingSampleFunction.FunctionName but 35 | # the SAM transformer and/or CF doesn't seem to like that... 36 | - LambdaInvokePolicy: {FunctionName: "*"} 37 | 38 | BandwidthFunction: 39 | Type: AWS::Serverless::Function 40 | Properties: 41 | CodeUri: src/ 42 | Handler: bandwidth.lambda_handler 43 | Timeout: 60 44 | MemorySize: 3008 45 | Layers: 46 | - "arn:aws:lambda:us-east-1:293602984666:layer:ServerlessNetworking-Python3:10" 47 | Policies: 48 | # TODO: This should ideally be something like !GetAtt BandwidthFunction.FunctionName but 49 | # the SAM transformer and/or CF doesn't seem to like that... 50 | - LambdaInvokePolicy: {FunctionName: "*"} 51 | -------------------------------------------------------------------------------- /aws/python/tests/speed.py: -------------------------------------------------------------------------------- 1 | import socket 2 | from sys import argv 3 | import time 4 | from udt4py import UDTSocket, UDTException 5 | 6 | 7 | if __name__ == "__main__": 8 | SIZE = 15 * 1000 * 1000 9 | msg = bytearray(SIZE) 10 | sock_type = argv[1][0:3] 11 | argv[1] = argv[1][6:] 12 | HOST, PORT = argv[1].split(':') 13 | addr = (HOST, int(PORT)) 14 | N = int(argv[2]) 15 | if sock_type == "udt": 16 | sock = UDTSocket() 17 | sock.UDP_SNDBUF = 512 * 1024 18 | sock.UDP_RCVBUF = 2 * 1024 * 1024 19 | sock.UDT_SNDBUF = (15 * 1000 + 1000) * 1000 20 | sock.UDT_RCVBUF = (15 * 1000 + 1000) * 1000 21 | elif sock_type == "tcp": 22 | sock = socket.socket() 23 | else: 24 | raise Exception("Socket type \"%s\" is not supported" % sock_type) 25 | if argv[1].startswith("0.0.0.0"): 26 | sock.bind(addr) 27 | sock.listen(1) 28 | peer, _ = sock.accept() 29 | start = time.time() 30 | all = 0 31 | if sock_type == "udt": 32 | while all < N * SIZE: 33 | all += peer.recv(msg) 34 | else: 35 | while all < N * SIZE: 36 | msg = peer.recv(4096) 37 | all += len(msg) 38 | peer.send(b'0') 39 | peer.close() 40 | else: 41 | sock.connect(addr) 42 | start = time.time() 43 | for i in range(N): 44 | sent = 0 45 | while (sent < len(msg)): 46 | chunk = sock.send(memoryview(msg)[0:len(msg)-sent]) 47 | sent += chunk 48 | if sock_type == "udt": 49 | bye = bytearray(1) 50 | sock.recv(bye) 51 | else: 52 | sock.recv(1) 53 | sock.close() 54 | delta = time.time() - start 55 | print("%.2f sec" % delta) 56 | -------------------------------------------------------------------------------- /aws/python/tests/udt_epoll.py: -------------------------------------------------------------------------------- 1 | """ 2 | Copyright (c) 2014, Samsung Electronics Co.,Ltd. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | 1. Redistributions of source code must retain the above copyright notice, this 9 | list of conditions and the following disclaimer. 10 | 2. Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 15 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR 18 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 23 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 | 25 | The views and conclusions contained in the software and documentation are those 26 | of the authors and should not be interpreted as representing official policies, 27 | either expressed or implied, of Samsung Electronics Co.,Ltd.. 28 | """ 29 | 30 | """ 31 | udt4py - libudt4 Cython-ish wrapper. 32 | URL: https://github.com/vmarkovtsev/udt4py 33 | Original author: Vadim Markovtsev 34 | 35 | libudt4 is (c)2001 - 2011, The Board of Trustees of the University of Illinois. 36 | libudt4 URL: http://udt.sourceforge.net/ 37 | """ 38 | 39 | """ 40 | UDTEpoll tests. 41 | """ 42 | 43 | 44 | import threading 45 | import time 46 | import unittest 47 | from udt4py import UDTSocket, UDTException, UDTEpoll 48 | 49 | 50 | class UDTEpollTest(unittest.TestCase): 51 | def testEpoll(self): 52 | self.socket = UDTSocket() 53 | self.socket.bind("0.0.0.0:7015") 54 | self.socket.listen() 55 | other_thread = threading.Thread(target=self.otherConnect) 56 | other_thread.start() 57 | sock, _ = self.socket.accept() 58 | poll = UDTEpoll() 59 | poll.add(sock) 60 | rs = [] 61 | while len(rs) == 0: 62 | rs, ws, _, _ = poll.wait() 63 | self.assertEqual(sock, rs[0]) 64 | self.assertEqual(sock, ws[0]) 65 | msg = bytearray(5) 66 | sock.recv(msg) 67 | 68 | def otherConnect(self): 69 | sock = UDTSocket() 70 | sock.connect("127.0.0.1:7015") 71 | self.assertEqual(UDTSocket.Status.CONNECTED, sock.status) 72 | sock.send(b"hello") 73 | 74 | if __name__ == "__main__": 75 | unittest.main() 76 | -------------------------------------------------------------------------------- /docs/CNAME: -------------------------------------------------------------------------------- 1 | networkingclients.serverlesstech.net -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-midnight -------------------------------------------------------------------------------- /docs/getting_started.md: -------------------------------------------------------------------------------- 1 | # Welcome to Serverless Networking! 2 | 3 | The beta release of Serverless Networking enables you to establish reliable communication between two non-VPC AWS Lambda functions. 4 | 5 | ## Fast path: 6 | The easiest way to get up and running is to [deploy the sample app in us-east-1 from the AWS Serverless App Repository.](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:293602984666:applications~ServerlessNetworkingPython3) This will create two sample functions, one that demonstrates basic buffer and file transfers, and a second that runs a bandwidth test. You can also clone the sample code, and the rest of the Serverless Networking client stack, from [its GitHub repo](https://github.com/serverlessunicorn/ServerlessNetworkingClients). 7 | 8 | 9 | ## Step-by-step guide to using Serverless Networking: 10 | 1. Setup. If you're not starting from the sample code, make sure you're in us-east-1 and have a 3.7 Python Lambda function created. Add the following layer ARN to your function: `arn:aws:lambda:us-east-1:293602984666:layer:ServerlessNetworking-Python3:9`. 11 | 12 | 1. Add imports: `from udt4py import UDTSocket, p2p_connect` 13 | 1. To communicate, you need both sides to execute the connection code. This can be two Lambda functions, two instances of the same Lambda function, a Lambda function and a server, etc. 14 | 15 | sock = p2p_connect(pairing_name) 16 | if (not sock or sock.status != UDTSocket.Status.CONNECTED): 17 | return { 18 | 'statusCode': 500, 19 | 'body': ('socket failed to rendezvous, state is:' + str(sock.status)) if sock else 'socket failed to pair' 20 | } 21 | 22 | 1. Sending data is easy - you can use the bytearray, byte (readonly bytearray), encoded strings, or memoryviews: 23 | 24 | bytes_sent1 = sock.send('Test 1'.encode('utf8')) 25 | bytes_sent2 = sock.send(bytes('Test 2', 'utf8')) 26 | bytes_sent3 = sock.send(memoryview(b'Test 3')) 27 | 28 | 1. Receiving is equally easy; if you're working with strings, you'll probably want to decode it into utf8. The code below shows how to avoid trailing NULLs in your string. 29 | 30 | buf = bytearray(20) 31 | len = sock.recv(buf) 32 | msg = buf[0:len].decode('utf8') 33 | 34 | 1. An example of transferring disk files (from Lambda's /tmp filesystem) is included in the sample code. 35 | 1. Other things you can do include sending datagram-like messages with lower reliability guarantees, poll for sockets that are ready to send or receive (UDTEpoll, similar to unix select), or retrieve performance data using perfmon(). 36 | 1. When you're finished with a socket, execute `sock.close()` for graceful shutdown. 37 | 1. Best practice is to recreate any sockets you need on each Lambda invocation; placing a socket in a global variable may lead to broken connections between Lambda invocations. (At a minimum, you should check the status of such a socket before attempting to reuse it on the next Lambda invoke.) 38 | 39 | ### API docs 40 | You can find additional API-level documentation using Python docstring and help features and in [the Cython sources](https://github.com/serverlessunicorn/ServerlessNetworkingClients/blob/master/aws/python/src/udt4py.pyx). 41 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | # Serverless Networking 2 | Serverless Networking adds back the "missing piece" of serverless functions, enabling you to perform distributed computations, high-speed workflows, easy to use async workers, pre-warmed capacity, inter-function file transfers, and much more. 3 | 4 | [Deploy the sample app in us-east-1 from the AWS Serverless App Repository](https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:293602984666:applications~ServerlessNetworkingPython3) 5 | 6 | ## Open source project and BSD license: 7 | [GitHub](https://github.com/serverlessunicorn/ServerlessNetworkingClients) 8 | [License](https://github.com/serverlessunicorn/ServerlessNetworkingClients/blob/master/LICENSE) 9 | 10 | ## FAQ 11 | [FAQ](FAQ.md) 12 | 13 | ## Getting started guide 14 | [User Guide](getting_started.md) 15 | -------------------------------------------------------------------------------- /docs/overview.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/docs/overview.md -------------------------------------------------------------------------------- /udt/udt4/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are 6 | met: 7 | 8 | * Redistributions of source code must retain the above 9 | copyright notice, this list of conditions and the 10 | following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the 13 | above copyright notice, this list of conditions 14 | and the following disclaimer in the documentation 15 | and/or other materials provided with the distribution. 16 | 17 | * Neither the name of the University of Illinois 18 | nor the names of its contributors may be used to 19 | endorse or promote products derived from this 20 | software without specific prior written permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 23 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 24 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 25 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | -------------------------------------------------------------------------------- /udt/udt4/Makefile: -------------------------------------------------------------------------------- 1 | DIRS = src app 2 | TARGETS = all clean install 3 | 4 | $(TARGETS): %: $(patsubst %, %.%, $(DIRS)) 5 | 6 | $(foreach TGT, $(TARGETS), $(patsubst %, %.$(TGT), $(DIRS))): 7 | $(MAKE) -C $(subst ., , $@) 8 | -------------------------------------------------------------------------------- /udt/udt4/README.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 2 | All Rights Reserved. 3 | Copyright (c) 2011 - 2012, Google, Inc. All Rights Reserved. 4 | 5 | UDP-based Data Transfer (UDT) Library - version 4 6 | Author: Yunhong Gu [yunhong.gu @ gmail.com] 7 | 8 | UDT version 4 is free software under BSD License. See ./LICENSE.txt. 9 | 10 | ============================================================================ 11 | 12 | UDT Website: 13 | http://udt.sf.net 14 | http://sf.net/projects/udt/ 15 | 16 | 17 | CONTENT: 18 | ./src: UDT source code 19 | ./app: Example programs 20 | ./doc: UDT documentation (HTML) 21 | ./win: Visual C++ project files for the Windows version of UDT 22 | 23 | 24 | To make: 25 | make -e os=XXX arch=YYY 26 | 27 | XXX: [LINUX(default), BSD, OSX] 28 | YYY: [IA32(default), POWERPC, IA64, AMD64] 29 | 30 | For example, on OS X, you may need to do "make -e os=OSX arch=POWERPC"; 31 | on 32-bit i386 Linux system, simply use "make". 32 | 33 | On Windows systems, use the Visual C++ project files in ./win directory. 34 | 35 | Note for BSD users, please use GNU Make. 36 | 37 | To use UDT in your application: 38 | Read index.htm in ./doc. The documentation is in HTML format and requires your 39 | browser to support JavaScript. 40 | 41 | 42 | Questions? please post to the UDT project forum: 43 | https://sourceforge.net/projects/udt/forums 44 | -------------------------------------------------------------------------------- /udt/udt4/RELEASE_NOTES.txt: -------------------------------------------------------------------------------- 1 | version 4.11 2 | 3 | mostly bug fixes since last version. 4 | 5 | version 4.10 6 | 7 | added UDT_SNDDATA and UDT_RCVDATA options 8 | fixed a bug that causes unnecessary connection timeout 9 | improved epoll UDT event handling 10 | 11 | version 4.9 12 | 13 | asynchronous close 14 | asynchronous connect 15 | some bug fixes, especially on EPOLL 16 | improved cache code 17 | removed unnecessary NAK (reduced loss retransmission) 18 | receiver side error can unblock a blocked sender 19 | 20 | version 4.8 21 | 22 | fix a bug that may cause seg fault on concurrent close on the same socket 23 | add epoll support 24 | increase the listener's scalability to 100K concurrent connections 25 | fix a bug that may cause accept/select to return positively when an accepted socket is closed immediately after accept returns 26 | fix a bug that may cause connect to fail if the server closes listening socket immediately after accept returns 27 | fix recvfile fstream write status bug (e.g., when disk is full, recvfile should handle properly now) 28 | 29 | version 4.7a 30 | 31 | fix timeout bug introduced in 4.7 32 | initialize CHandShake 33 | 34 | version 4.7 35 | 36 | Fix several related bugs that can cause hang/memory leak/segmentation fault during cleanup() 37 | -------------------------------------------------------------------------------- /udt/udt4/app/Makefile: -------------------------------------------------------------------------------- 1 | C++ = g++ 2 | 3 | ifndef os 4 | os = LINUX 5 | endif 6 | 7 | ifndef arch 8 | arch = IA32 9 | endif 10 | 11 | CCFLAGS = -Wall -D$(os) -I../src -finline-functions -O3 12 | 13 | ifeq ($(arch), IA32) 14 | CCFLAGS += -DIA32 #-mcpu=pentiumpro -march=pentiumpro -mmmx -msse 15 | endif 16 | 17 | ifeq ($(arch), POWERPC) 18 | CCFLAGS += -mcpu=powerpc 19 | endif 20 | 21 | ifeq ($(arch), IA64) 22 | CCFLAGS += -DIA64 23 | endif 24 | 25 | ifeq ($(arch), SPARC) 26 | CCFLAGS += -DSPARC 27 | endif 28 | 29 | LDFLAGS = -L../src -ludt -lstdc++ -lpthread -lm 30 | 31 | ifeq ($(os), UNIX) 32 | LDFLAGS += -lsocket 33 | endif 34 | 35 | ifeq ($(os), SUNOS) 36 | LDFLAGS += -lrt -lsocket 37 | endif 38 | 39 | DIR = $(shell pwd) 40 | 41 | APP = appserver appclient sendfile recvfile test 42 | 43 | all: $(APP) 44 | 45 | %.o: %.cpp 46 | $(C++) $(CCFLAGS) $< -c 47 | 48 | appserver: appserver.o 49 | $(C++) $^ -o $@ $(LDFLAGS) 50 | appclient: appclient.o 51 | $(C++) $^ -o $@ $(LDFLAGS) 52 | sendfile: sendfile.o 53 | $(C++) $^ -o $@ $(LDFLAGS) 54 | recvfile: recvfile.o 55 | $(C++) $^ -o $@ $(LDFLAGS) 56 | test: test.o 57 | $(C++) $^ -o $@ $(LDFLAGS) 58 | 59 | clean: 60 | rm -f *.o $(APP) 61 | 62 | install: 63 | export PATH=$(DIR):$$PATH 64 | -------------------------------------------------------------------------------- /udt/udt4/app/appclient.cpp: -------------------------------------------------------------------------------- 1 | #ifndef WIN32 2 | #include 3 | #include 4 | #include 5 | #include 6 | #else 7 | #include 8 | #include 9 | #include 10 | #endif 11 | #include 12 | #include 13 | #include "cc.h" 14 | #include "test_util.h" 15 | 16 | using namespace std; 17 | 18 | #ifndef WIN32 19 | void* monitor(void*); 20 | #else 21 | DWORD WINAPI monitor(LPVOID); 22 | #endif 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | if ((3 != argc) || (0 == atoi(argv[2]))) 27 | { 28 | cout << "usage: appclient server_ip server_port" << endl; 29 | return 0; 30 | } 31 | 32 | // Automatically start up and clean up UDT module. 33 | UDTUpDown _udt_; 34 | 35 | struct addrinfo hints, *local, *peer; 36 | 37 | memset(&hints, 0, sizeof(struct addrinfo)); 38 | 39 | hints.ai_flags = AI_PASSIVE; 40 | hints.ai_family = AF_INET; 41 | hints.ai_socktype = SOCK_STREAM; 42 | //hints.ai_socktype = SOCK_DGRAM; 43 | 44 | if (0 != getaddrinfo(NULL, "9000", &hints, &local)) 45 | { 46 | cout << "incorrect network address.\n" << endl; 47 | return 0; 48 | } 49 | 50 | UDTSOCKET client = UDT::socket(local->ai_family, local->ai_socktype, local->ai_protocol); 51 | 52 | // UDT Options 53 | //UDT::setsockopt(client, 0, UDT_CC, new CCCFactory, sizeof(CCCFactory)); 54 | //UDT::setsockopt(client, 0, UDT_MSS, new int(9000), sizeof(int)); 55 | //UDT::setsockopt(client, 0, UDT_SNDBUF, new int(10000000), sizeof(int)); 56 | //UDT::setsockopt(client, 0, UDP_SNDBUF, new int(10000000), sizeof(int)); 57 | //UDT::setsockopt(client, 0, UDT_MAXBW, new int64_t(12500000), sizeof(int)); 58 | 59 | // Windows UDP issue 60 | // For better performance, modify HKLM\System\CurrentControlSet\Services\Afd\Parameters\FastSendDatagramThreshold 61 | #ifdef WIN32 62 | UDT::setsockopt(client, 0, UDT_MSS, new int(1052), sizeof(int)); 63 | #endif 64 | 65 | // for rendezvous connection, enable the code below 66 | /* 67 | UDT::setsockopt(client, 0, UDT_RENDEZVOUS, new bool(true), sizeof(bool)); 68 | if (UDT::ERROR == UDT::bind(client, local->ai_addr, local->ai_addrlen)) 69 | { 70 | cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl; 71 | return 0; 72 | } 73 | */ 74 | 75 | freeaddrinfo(local); 76 | 77 | if (0 != getaddrinfo(argv[1], argv[2], &hints, &peer)) 78 | { 79 | cout << "incorrect server/peer address. " << argv[1] << ":" << argv[2] << endl; 80 | return 0; 81 | } 82 | 83 | // connect to the server, implict bind 84 | if (UDT::ERROR == UDT::connect(client, peer->ai_addr, peer->ai_addrlen)) 85 | { 86 | cout << "connect: " << UDT::getlasterror().getErrorMessage() << endl; 87 | return 0; 88 | } 89 | 90 | freeaddrinfo(peer); 91 | 92 | // using CC method 93 | //CUDPBlast* cchandle = NULL; 94 | //int temp; 95 | //UDT::getsockopt(client, 0, UDT_CC, &cchandle, &temp); 96 | //if (NULL != cchandle) 97 | // cchandle->setRate(500); 98 | 99 | int size = 100000; 100 | char* data = new char[size]; 101 | 102 | #ifndef WIN32 103 | pthread_create(new pthread_t, NULL, monitor, &client); 104 | #else 105 | CreateThread(NULL, 0, monitor, &client, 0, NULL); 106 | #endif 107 | 108 | for (int i = 0; i < 1000000; i ++) 109 | { 110 | int ssize = 0; 111 | int ss; 112 | while (ssize < size) 113 | { 114 | if (UDT::ERROR == (ss = UDT::send(client, data + ssize, size - ssize, 0))) 115 | { 116 | cout << "send:" << UDT::getlasterror().getErrorMessage() << endl; 117 | break; 118 | } 119 | 120 | ssize += ss; 121 | } 122 | 123 | if (ssize < size) 124 | break; 125 | } 126 | 127 | UDT::close(client); 128 | delete [] data; 129 | return 0; 130 | } 131 | 132 | #ifndef WIN32 133 | void* monitor(void* s) 134 | #else 135 | DWORD WINAPI monitor(LPVOID s) 136 | #endif 137 | { 138 | UDTSOCKET u = *(UDTSOCKET*)s; 139 | 140 | UDT::TRACEINFO perf; 141 | 142 | cout << "SendRate(Mb/s)\tRTT(ms)\tCWnd\tPktSndPeriod(us)\tRecvACK\tRecvNAK" << endl; 143 | 144 | while (true) 145 | { 146 | #ifndef WIN32 147 | sleep(1); 148 | #else 149 | Sleep(1000); 150 | #endif 151 | 152 | if (UDT::ERROR == UDT::perfmon(u, &perf)) 153 | { 154 | cout << "perfmon: " << UDT::getlasterror().getErrorMessage() << endl; 155 | break; 156 | } 157 | 158 | cout << perf.mbpsSendRate << "\t\t" 159 | << perf.msRTT << "\t" 160 | << perf.pktCongestionWindow << "\t" 161 | << perf.usPktSndPeriod << "\t\t\t" 162 | << perf.pktRecvACK << "\t" 163 | << perf.pktRecvNAK << endl; 164 | } 165 | 166 | #ifndef WIN32 167 | return NULL; 168 | #else 169 | return 0; 170 | #endif 171 | } 172 | -------------------------------------------------------------------------------- /udt/udt4/app/appserver.cpp: -------------------------------------------------------------------------------- 1 | #ifndef WIN32 2 | #include 3 | #include 4 | #include 5 | #include 6 | #else 7 | #include 8 | #include 9 | #include 10 | #endif 11 | #include 12 | #include 13 | #include "cc.h" 14 | #include "test_util.h" 15 | 16 | using namespace std; 17 | 18 | #ifndef WIN32 19 | void* recvdata(void*); 20 | #else 21 | DWORD WINAPI recvdata(LPVOID); 22 | #endif 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | if ((1 != argc) && ((2 != argc) || (0 == atoi(argv[1])))) 27 | { 28 | cout << "usage: appserver [server_port]" << endl; 29 | return 0; 30 | } 31 | 32 | // Automatically start up and clean up UDT module. 33 | UDTUpDown _udt_; 34 | 35 | addrinfo hints; 36 | addrinfo* res; 37 | 38 | memset(&hints, 0, sizeof(struct addrinfo)); 39 | 40 | hints.ai_flags = AI_PASSIVE; 41 | hints.ai_family = AF_INET; 42 | hints.ai_socktype = SOCK_STREAM; 43 | //hints.ai_socktype = SOCK_DGRAM; 44 | 45 | string service("9000"); 46 | if (2 == argc) 47 | service = argv[1]; 48 | 49 | if (0 != getaddrinfo(NULL, service.c_str(), &hints, &res)) 50 | { 51 | cout << "illegal port number or port is busy.\n" << endl; 52 | return 0; 53 | } 54 | 55 | UDTSOCKET serv = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protocol); 56 | 57 | // UDT Options 58 | //UDT::setsockopt(serv, 0, UDT_CC, new CCCFactory, sizeof(CCCFactory)); 59 | //UDT::setsockopt(serv, 0, UDT_MSS, new int(9000), sizeof(int)); 60 | //UDT::setsockopt(serv, 0, UDT_RCVBUF, new int(10000000), sizeof(int)); 61 | //UDT::setsockopt(serv, 0, UDP_RCVBUF, new int(10000000), sizeof(int)); 62 | 63 | if (UDT::ERROR == UDT::bind(serv, res->ai_addr, res->ai_addrlen)) 64 | { 65 | cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl; 66 | return 0; 67 | } 68 | 69 | freeaddrinfo(res); 70 | 71 | cout << "server is ready at port: " << service << endl; 72 | 73 | if (UDT::ERROR == UDT::listen(serv, 10)) 74 | { 75 | cout << "listen: " << UDT::getlasterror().getErrorMessage() << endl; 76 | return 0; 77 | } 78 | 79 | sockaddr_storage clientaddr; 80 | int addrlen = sizeof(clientaddr); 81 | 82 | UDTSOCKET recver; 83 | 84 | while (true) 85 | { 86 | if (UDT::INVALID_SOCK == (recver = UDT::accept(serv, (sockaddr*)&clientaddr, &addrlen))) 87 | { 88 | cout << "accept: " << UDT::getlasterror().getErrorMessage() << endl; 89 | return 0; 90 | } 91 | 92 | char clienthost[NI_MAXHOST]; 93 | char clientservice[NI_MAXSERV]; 94 | getnameinfo((sockaddr *)&clientaddr, addrlen, clienthost, sizeof(clienthost), clientservice, sizeof(clientservice), NI_NUMERICHOST|NI_NUMERICSERV); 95 | cout << "new connection: " << clienthost << ":" << clientservice << endl; 96 | 97 | #ifndef WIN32 98 | pthread_t rcvthread; 99 | pthread_create(&rcvthread, NULL, recvdata, new UDTSOCKET(recver)); 100 | pthread_detach(rcvthread); 101 | #else 102 | CreateThread(NULL, 0, recvdata, new UDTSOCKET(recver), 0, NULL); 103 | #endif 104 | } 105 | 106 | UDT::close(serv); 107 | 108 | return 0; 109 | } 110 | 111 | #ifndef WIN32 112 | void* recvdata(void* usocket) 113 | #else 114 | DWORD WINAPI recvdata(LPVOID usocket) 115 | #endif 116 | { 117 | UDTSOCKET recver = *(UDTSOCKET*)usocket; 118 | delete (UDTSOCKET*)usocket; 119 | 120 | char* data; 121 | int size = 100000; 122 | data = new char[size]; 123 | 124 | while (true) 125 | { 126 | int rsize = 0; 127 | int rs; 128 | while (rsize < size) 129 | { 130 | int rcv_size; 131 | int var_size = sizeof(int); 132 | UDT::getsockopt(recver, 0, UDT_RCVDATA, &rcv_size, &var_size); 133 | if (UDT::ERROR == (rs = UDT::recv(recver, data + rsize, size - rsize, 0))) 134 | { 135 | cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl; 136 | break; 137 | } 138 | 139 | rsize += rs; 140 | } 141 | 142 | if (rsize < size) 143 | break; 144 | } 145 | 146 | delete [] data; 147 | 148 | UDT::close(recver); 149 | 150 | #ifndef WIN32 151 | return NULL; 152 | #else 153 | return 0; 154 | #endif 155 | } 156 | -------------------------------------------------------------------------------- /udt/udt4/app/cc.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | class CTCP: public CCC 5 | { 6 | public: 7 | void init() 8 | { 9 | m_bSlowStart = true; 10 | m_issthresh = 83333; 11 | 12 | m_dPktSndPeriod = 0.0; 13 | m_dCWndSize = 2.0; 14 | 15 | setACKInterval(2); 16 | setRTO(1000000); 17 | } 18 | 19 | virtual void onACK(const int& ack) 20 | { 21 | if (ack == m_iLastACK) 22 | { 23 | if (3 == ++ m_iDupACKCount) 24 | DupACKAction(); 25 | else if (m_iDupACKCount > 3) 26 | m_dCWndSize += 1.0; 27 | else 28 | ACKAction(); 29 | } 30 | else 31 | { 32 | if (m_iDupACKCount >= 3) 33 | m_dCWndSize = m_issthresh; 34 | 35 | m_iLastACK = ack; 36 | m_iDupACKCount = 1; 37 | 38 | ACKAction(); 39 | } 40 | } 41 | 42 | virtual void onTimeout() 43 | { 44 | m_issthresh = getPerfInfo()->pktFlightSize / 2; 45 | if (m_issthresh < 2) 46 | m_issthresh = 2; 47 | 48 | m_bSlowStart = true; 49 | m_dCWndSize = 2.0; 50 | } 51 | 52 | protected: 53 | virtual void ACKAction() 54 | { 55 | if (m_bSlowStart) 56 | { 57 | m_dCWndSize += 1.0; 58 | 59 | if (m_dCWndSize >= m_issthresh) 60 | m_bSlowStart = false; 61 | } 62 | else 63 | m_dCWndSize += 1.0/m_dCWndSize; 64 | } 65 | 66 | virtual void DupACKAction() 67 | { 68 | m_bSlowStart = false; 69 | 70 | m_issthresh = getPerfInfo()->pktFlightSize / 2; 71 | if (m_issthresh < 2) 72 | m_issthresh = 2; 73 | 74 | m_dCWndSize = m_issthresh + 3; 75 | } 76 | 77 | protected: 78 | int m_issthresh; 79 | bool m_bSlowStart; 80 | 81 | int m_iDupACKCount; 82 | int m_iLastACK; 83 | }; 84 | 85 | 86 | class CUDPBlast: public CCC 87 | { 88 | public: 89 | CUDPBlast() 90 | { 91 | m_dPktSndPeriod = 1000000; 92 | m_dCWndSize = 83333.0; 93 | } 94 | 95 | public: 96 | void setRate(double mbps) 97 | { 98 | m_dPktSndPeriod = (m_iMSS * 8.0) / mbps; 99 | } 100 | }; 101 | -------------------------------------------------------------------------------- /udt/udt4/app/recvfile.cpp: -------------------------------------------------------------------------------- 1 | #ifndef WIN32 2 | #include 3 | #include 4 | #else 5 | #include 6 | #include 7 | #endif 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | using namespace std; 15 | 16 | int main(int argc, char* argv[]) 17 | { 18 | if ((argc != 5) || (0 == atoi(argv[2]))) 19 | { 20 | cout << "usage: recvfile server_ip server_port remote_filename local_filename" << endl; 21 | return -1; 22 | } 23 | 24 | // use this function to initialize the UDT library 25 | UDT::startup(); 26 | 27 | struct addrinfo hints, *peer; 28 | 29 | memset(&hints, 0, sizeof(struct addrinfo)); 30 | hints.ai_flags = AI_PASSIVE; 31 | hints.ai_family = AF_INET; 32 | hints.ai_socktype = SOCK_STREAM; 33 | 34 | UDTSOCKET fhandle = UDT::socket(hints.ai_family, hints.ai_socktype, hints.ai_protocol); 35 | 36 | if (0 != getaddrinfo(argv[1], argv[2], &hints, &peer)) 37 | { 38 | cout << "incorrect server/peer address. " << argv[1] << ":" << argv[2] << endl; 39 | return -1; 40 | } 41 | 42 | // connect to the server, implict bind 43 | if (UDT::ERROR == UDT::connect(fhandle, peer->ai_addr, peer->ai_addrlen)) 44 | { 45 | cout << "connect: " << UDT::getlasterror().getErrorMessage() << endl; 46 | return -1; 47 | } 48 | 49 | freeaddrinfo(peer); 50 | 51 | 52 | // send name information of the requested file 53 | int len = strlen(argv[3]); 54 | 55 | if (UDT::ERROR == UDT::send(fhandle, (char*)&len, sizeof(int), 0)) 56 | { 57 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 58 | return -1; 59 | } 60 | 61 | if (UDT::ERROR == UDT::send(fhandle, argv[3], len, 0)) 62 | { 63 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 64 | return -1; 65 | } 66 | 67 | // get size information 68 | int64_t size; 69 | 70 | if (UDT::ERROR == UDT::recv(fhandle, (char*)&size, sizeof(int64_t), 0)) 71 | { 72 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 73 | return -1; 74 | } 75 | 76 | if (size < 0) 77 | { 78 | cout << "no such file " << argv[3] << " on the server\n"; 79 | return -1; 80 | } 81 | 82 | // receive the file 83 | fstream ofs(argv[4], ios::out | ios::binary | ios::trunc); 84 | int64_t recvsize; 85 | int64_t offset = 0; 86 | 87 | if (UDT::ERROR == (recvsize = UDT::recvfile(fhandle, ofs, offset, size))) 88 | { 89 | cout << "recvfile: " << UDT::getlasterror().getErrorMessage() << endl; 90 | return -1; 91 | } 92 | 93 | UDT::close(fhandle); 94 | 95 | ofs.close(); 96 | 97 | // use this function to release the UDT library 98 | UDT::cleanup(); 99 | 100 | return 0; 101 | } 102 | -------------------------------------------------------------------------------- /udt/udt4/app/sendfile.cpp: -------------------------------------------------------------------------------- 1 | #ifndef WIN32 2 | #include 3 | #include 4 | #else 5 | #include 6 | #include 7 | #endif 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | using namespace std; 14 | 15 | #ifndef WIN32 16 | void* sendfile(void*); 17 | #else 18 | DWORD WINAPI sendfile(LPVOID); 19 | #endif 20 | 21 | int main(int argc, char* argv[]) 22 | { 23 | //usage: sendfile [server_port] 24 | if ((2 < argc) || ((2 == argc) && (0 == atoi(argv[1])))) 25 | { 26 | cout << "usage: sendfile [server_port]" << endl; 27 | return 0; 28 | } 29 | 30 | // use this function to initialize the UDT library 31 | UDT::startup(); 32 | 33 | addrinfo hints; 34 | addrinfo* res; 35 | 36 | memset(&hints, 0, sizeof(struct addrinfo)); 37 | hints.ai_flags = AI_PASSIVE; 38 | hints.ai_family = AF_INET; 39 | hints.ai_socktype = SOCK_STREAM; 40 | 41 | string service("9000"); 42 | if (2 == argc) 43 | service = argv[1]; 44 | 45 | if (0 != getaddrinfo(NULL, service.c_str(), &hints, &res)) 46 | { 47 | cout << "illegal port number or port is busy.\n" << endl; 48 | return 0; 49 | } 50 | 51 | UDTSOCKET serv = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protocol); 52 | 53 | // Windows UDP issue 54 | // For better performance, modify HKLM\System\CurrentControlSet\Services\Afd\Parameters\FastSendDatagramThreshold 55 | #ifdef WIN32 56 | int mss = 1052; 57 | UDT::setsockopt(serv, 0, UDT_MSS, &mss, sizeof(int)); 58 | #endif 59 | 60 | if (UDT::ERROR == UDT::bind(serv, res->ai_addr, res->ai_addrlen)) 61 | { 62 | cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl; 63 | return 0; 64 | } 65 | 66 | freeaddrinfo(res); 67 | 68 | cout << "server is ready at port: " << service << endl; 69 | 70 | UDT::listen(serv, 10); 71 | 72 | sockaddr_storage clientaddr; 73 | int addrlen = sizeof(clientaddr); 74 | 75 | UDTSOCKET fhandle; 76 | 77 | while (true) 78 | { 79 | if (UDT::INVALID_SOCK == (fhandle = UDT::accept(serv, (sockaddr*)&clientaddr, &addrlen))) 80 | { 81 | cout << "accept: " << UDT::getlasterror().getErrorMessage() << endl; 82 | return 0; 83 | } 84 | 85 | char clienthost[NI_MAXHOST]; 86 | char clientservice[NI_MAXSERV]; 87 | getnameinfo((sockaddr *)&clientaddr, addrlen, clienthost, sizeof(clienthost), clientservice, sizeof(clientservice), NI_NUMERICHOST|NI_NUMERICSERV); 88 | cout << "new connection: " << clienthost << ":" << clientservice << endl; 89 | 90 | #ifndef WIN32 91 | pthread_t filethread; 92 | pthread_create(&filethread, NULL, sendfile, new UDTSOCKET(fhandle)); 93 | pthread_detach(filethread); 94 | #else 95 | CreateThread(NULL, 0, sendfile, new UDTSOCKET(fhandle), 0, NULL); 96 | #endif 97 | } 98 | 99 | UDT::close(serv); 100 | 101 | // use this function to release the UDT library 102 | UDT::cleanup(); 103 | 104 | return 0; 105 | } 106 | 107 | #ifndef WIN32 108 | void* sendfile(void* usocket) 109 | #else 110 | DWORD WINAPI sendfile(LPVOID usocket) 111 | #endif 112 | { 113 | UDTSOCKET fhandle = *(UDTSOCKET*)usocket; 114 | delete (UDTSOCKET*)usocket; 115 | 116 | // aquiring file name information from client 117 | char file[1024]; 118 | int len; 119 | 120 | if (UDT::ERROR == UDT::recv(fhandle, (char*)&len, sizeof(int), 0)) 121 | { 122 | cout << "recv: " << UDT::getlasterror().getErrorMessage() << endl; 123 | return 0; 124 | } 125 | 126 | if (UDT::ERROR == UDT::recv(fhandle, file, len, 0)) 127 | { 128 | cout << "recv: " << UDT::getlasterror().getErrorMessage() << endl; 129 | return 0; 130 | } 131 | file[len] = '\0'; 132 | 133 | // open the file 134 | fstream ifs(file, ios::in | ios::binary); 135 | 136 | ifs.seekg(0, ios::end); 137 | int64_t size = ifs.tellg(); 138 | ifs.seekg(0, ios::beg); 139 | 140 | // send file size information 141 | if (UDT::ERROR == UDT::send(fhandle, (char*)&size, sizeof(int64_t), 0)) 142 | { 143 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 144 | return 0; 145 | } 146 | 147 | UDT::TRACEINFO trace; 148 | UDT::perfmon(fhandle, &trace); 149 | 150 | // send the file 151 | int64_t offset = 0; 152 | if (UDT::ERROR == UDT::sendfile(fhandle, ifs, offset, size)) 153 | { 154 | cout << "sendfile: " << UDT::getlasterror().getErrorMessage() << endl; 155 | return 0; 156 | } 157 | 158 | UDT::perfmon(fhandle, &trace); 159 | cout << "speed = " << trace.mbpsSendRate << "Mbits/sec" << endl; 160 | 161 | UDT::close(fhandle); 162 | 163 | ifs.close(); 164 | 165 | #ifndef WIN32 166 | return NULL; 167 | #else 168 | return 0; 169 | #endif 170 | } 171 | -------------------------------------------------------------------------------- /udt/udt4/app/test_util.h: -------------------------------------------------------------------------------- 1 | #ifndef _UDT_TEST_UTIL_H_ 2 | #define _UDT_TEST_UTIL_H_ 3 | 4 | struct UDTUpDown{ 5 | UDTUpDown() 6 | { 7 | // use this function to initialize the UDT library 8 | UDT::startup(); 9 | } 10 | ~UDTUpDown() 11 | { 12 | // use this function to release the UDT library 13 | UDT::cleanup(); 14 | } 15 | }; 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/accept.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

accept

13 |

The accept method retrieves an incoming connection.

14 | 15 |
UDTSOCKET accept(
16 |   UDTSOCKET u,
17 |   struct sockaddr* addr,
18 |   int* addrlen
19 | );
20 | 21 |
Parameters
22 |
23 |
u
24 |
[in] Descriptor identifying a listening socket.
25 |
addr
26 |
[out] Address of the peer side of the new accepted connection.
27 |
addrlen
28 |
[out] Length of the addr structure.
29 |
30 | 31 |
Return Value
32 |

If no error occurs, accept returns the UDT socket descriptor of the new connection; otherwise, it returns 33 | UDT::INVALID_SOCK.

34 |

On a successful return, the address of the peer 35 | side of the connection is written into addr, and its length is in addrlen, if the addr parameter is not NULL.

36 |

If an error is returned, the error information 37 | can be retrieved by getlasterror. One of the following error can cause an accept error:

38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 |
Error NameError CodeComment
EINVSOCK5004u is an invalid UDT socket.
ENOLISTEN5006u is not in the listening state.
ERDVNOSERV5007u is set up to support rendezvous connection.
EASYNCRCV6002u is non-blocking (UDT_RCVSYN = false) but there is no connection available.
66 | 67 |
Description
68 |

Once a UDT socket is in listening state, it accepts new connections and maintains the pending connections in a queue. An accept call retrieves 69 | the first connection in the queue, removes it from the queue, and returns the associate socket descriptor.

70 |

If there is no connections in the queue when accept is called, a blocking socket will wait until a new connection is set up, whereas a 71 | non-blocking socket will return immediately with an error.

72 |

The accepted sockets will inherit all proper attributes from the listening socket.

73 | 74 |
See Also
75 |

listen, connect, setsockopt, getsockopt

76 |

 

77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/bind.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

bind

13 |

The bind method binds a UDT socket to a known or an available local address.

14 | 15 |
16 | int bind(
17 |   UDTSOCKET u,
18 |   struct sockaddr* name,
19 |   int* namelen
20 | ); 21 |

22 | int bind(
23 | #ifndef WIN32
24 |   int udpsock
25 | #else
26 |   SOCKET udpsock
27 | #endif
28 | ); 29 |
30 | 31 |
Parameters
32 |
33 |
u
34 |
[in] Descriptor identifying a UDT socket.
35 |
name
36 |
[out] Address to assign to the socket from the sockaddr structure.
37 |
namelen
38 |
[out] Length of the name structure.
39 |
udpsock
40 |
[in] An existing UDP socket for UDT to bind.
41 |
42 | 43 |
Return Value
44 |

If the binding is successful, bind returns 0, otherwise it returns UDT::ERROR and the specific error information can be retrieved using getlasterror.

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 |
Error NameError CodeComment
EBOUNDSOCK5001u has already been bound to certain address.
EINVPARAM5003the address is either invalid or unavailable.
EINVSOCK5004u is an invalid UDT socket.
69 | 70 |
Description
71 |

The bind method is usually to assign a UDT socket a local address, including IP address and port number. If INADDR_ANY is used, a proper IP address will be used once 72 | the UDT connection is set up. If 0 is used for the port, a randomly available port number will be used. The method getsockname can be used to retrieve this port 73 | number.

74 |

The second form of bind allows UDT to bind directly on an existing UDP socket. This is usefule for firewall traversing in certain situations: 1) a UDP socket is created and its address is learned from a name server, there is no need to close the UDP socket and open a UDT socket on the same address again; 2) for certain firewall, especially some on local system, the port mapping maybe changed or the "hole" may be closed when a UDP socket is closed and reopened, thus it is necessary to use the UDP socket directly in UDT.

75 |

Use the second form of bind with caution, as it violates certain programming rules regarding code robustness. Once the UDP socket descriptor is passed to UDT, it MUST NOT be touched again. DO NOT use this unless you clearly understand how the related systems work.

76 |

The bind call is necessary in all cases except for a socket to listen. If bind is not called, UDT will automatically bind a 77 | socket to a randomly available address when a connection is set up.

78 |

By default, UDT allows to reuse existing UDP port for new UDT sockets, unless UDT_REUSEADDR is set to false. When UDT_REUSEADDR is false, UDT will create an 79 | exclusive UDP port for this UDT socket. UDT_REUSEADDR must be called before bind. To reuse an existing UDT/UDP port, the new UDT socket must 80 | explicitly bind to the port. If the port is already used by a UDT socket with UDT_REUSEADDR as false, the new bind will return error. If 0 is passed 81 | as the port number, bind always creates a new port, no matter what value the UDT_REUSEADDR sets.

82 | 83 |
See Also
84 |

listen, connect, setsockopt, getsockopt

85 |

 

86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/cleanup.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

cleanup

13 |

The cleanup method releases the UDT library from your application.

14 | 15 |
int cleanup(
16 | );
17 | 18 |
Parameters
19 |
20 |
None.
21 |
22 | 23 |
Return Value
24 |

If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

25 |

In the current version, this method always succeed.

26 |
Description
27 |

The cleanup method releases the UDT library. All the remaining open connections will be closed. The background garbage collection is closed. However, this method will do nothing if no startup was ever called, or this is a repeated cleanup call.

28 |

The method must be called before the application exits, or before the UDT DLL is released, otherwise memory leak could happen.

29 |
See Also
30 |

startup

31 |

 

32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/close.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

close

13 |

The close method closes a UDT connection.

14 | 15 |
int close(
16 |   UDTSOCKET u
17 | );
18 | 19 |
Parameters
20 |
21 |
u
22 |
[in] Descriptor identifying the socket to close.
23 |
24 | 25 |
Return Value
26 |

If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
Error NameError CodeComment
EINVSOCK5004u is an invalid UDT socket.
40 | 41 |
Description
42 |

The close method gracefully shutdowns the UDT connection and releases all related data structures associated with the UDT socket. If there is no connection associated 43 | with the socket, close simply release the socket resources.

44 |

On a blocking socket, if UDT_LINGER is non-zero, the close call will wait until all data in the sending buffer are sent out or the waiting time has exceeded the 45 | expiration time set by UDT_LINGER. However, if UDT_SYNSND is set to false (i.e., non-blocking sending), close will return immediately and any linger data will be sent at background until the linger timer expires.

46 |

The closing UDT socket will send a shutdown message to the peer side so that the peer socket will also be closed. This is a best-effort message. If the message is not successfully 47 | delivered, the peer side will also be closed after a time-out. In UDT, shutdown is not supported.

48 |

All sockets should be closed if they are not used any more.

49 | 50 |
See Also
51 |

socket, setsockopt

52 |

 

53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/connect.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

connect

13 |

The connect method connects to a server socket (in regular mode) or a peer socket (in rendezvous mode) to set up a UDT connection.

14 | 15 |
int connect(
16 |   UDTSOCKET u,
17 |   const struct sockaddr* name,
18 |   int* namelen
19 | );
20 | 21 |
Parameters
22 |
23 |
u
24 |
[in] Descriptor identifying a socket.
25 |
name
26 |
[out] Address of the server or the peer socket.
27 |
namelen
28 |
[out] Length of the name structure.
29 |
30 | 31 |
Return Value
32 |

If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 |
Error NameError CodeComment
ENOSERVER1001server or peer socket does not exist, or there is no network connection.
ECONNREJ1002the connection request was rejected by the peer.
ESECFAIL1004connection was aborted due to possible attacks.
ECONNSOCK5002the socket is not allowed to do a connectconnect call; it is either in listening state or has been already connected.
EINVSOCK5004u is not a valid socket ID.
ERDVUNBOUND5008the rendezvous mode has been enable, but bind was not called before connect.
71 | 72 |
Description
73 |

UDT is connection oriented, for both of its SOCK_STREAM and SOCK_DGRAM mode. connect must be called in order to set up a UDT connection. The name parameter is 74 | the address of the server or the peer side. In regular (default) client/server mode, the server side must has called bind and listen. In rendezvous mode, 75 | both sides must call bind and connect to each other at (approximately) the same time. Rendezvous connect may not be used for more than one connections on the same UDP port pair, in which case UDT_REUSEADDR may be set to false.

76 |

UDT connect takes at least one round trip to finish. This may become a bottleneck if applications frequently connect and disconnect to the same address.

77 |

When UDT_RCVSYN is set to false, the connect call will return immediately and perform the actual connection setup at background. Applications may use epoll to wait for the connect to complete.

78 |

When connect fails, the UDT socket can still be used to connect again. However, if the socket was not bound before, it may be bound implicitly, as mentioned above, even 79 | if the connect fails. In addition, in the situation when the connect call fails, the UDT socket will not be automatically released, it is the applications' responsibility to close the socket, if the socket is not needed anymore (e.g., to re-connect).

80 | 81 |
See Also
82 |

listen, bind

83 |

 

84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/copy.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Copyright & License
11 | 12 |

Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois.
13 | All rights reserved.

14 |

Redistribution and use in source and binary forms, with or without 15 | modification, are permitted provided that the following conditions are 16 | met:

17 |
    18 |
  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. 19 |
  3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation 20 | and/or other materials provided with the distribution.
  4. 21 |
  5. Neither the name of the University of Illinois 22 | nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
  6. 23 |
24 |

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 25 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 26 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 27 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 28 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 29 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 30 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 31 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 32 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 34 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 |

36 |

 

37 | 38 | 39 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/error.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

getlasterror

13 |

The getlasterror method the last UDT error within the same thread.

14 | 15 |
ERRORINFO& getlasterror(
16 | );
17 | 18 |
Parameters
19 |
20 |
None.
21 |
22 | 23 |
Return Value
24 |

The last UDT error within the same thread is retrieved and returned in an ERRORINFO structure. If there is no error, a special SUCCESS code (0) will be 25 | returned. The getlasterror will always succeed. The returned value is a reference to the internal UDT ERRORINFO structure and application may clear it if necessary.

26 | 27 |
Description
28 |

The getlasterror method reads the last UDT error in the thread where this method is called. The error information is stored in thread specific storage.

29 | 30 |
See Also
31 |

Error Code List, Error Handling

32 |

 

33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/footer.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | footer 6 | 7 | 8 | 9 | 10 |
11 | Copyright © 2001 - 2011 Yunhong Gu. All rights reserved.
12 | Last modified: Tuesday, February 8, 2011 1:10 PM. 13 | 14 | 15 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/function.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

UDT Socket Functions

13 | 14 |

The UDT socket functions are contained in the UDT namespace. The methods are listed in the table below:

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 |
MethodFuctionality
acceptaccept a connection.
bindassign a local name to an unnamed udt socket.
cleanuprelease the complete UDT library.
closeclose the opened UDT entity and shutdown the connection.
connectconnect to the server or the peer side.
epollwatch for a group of UDT and system sockets for IO events.
getlasterrorretrieve last UDT error in the current thread.
getpeernameread the address of the peer side of the connection
getsocknameread the local address of the UDT socket.
getsockoptread UDT options.
listenenable UDT into listening state and is ready for connection request.
perfmonmonitor internal protocol parameters and udt performance.
recvreceive data.
recvfilereceive data into a file.
recvmsgreceive a message.
selectwait for a number of UDT sockets to change status.
sendsend data.
sendfilesend a file.
sendmsgsend a message.
setsockoptconfigure UDT options.
socketcreate a new UDT socket.
startupinitialize the UDT library.
110 | 111 |
See Also
112 |

UDT Socket Structures

113 | 114 |

 

115 | 116 | 117 | 118 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/header.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Untitled Document 6 | 7 | 8 | 9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/intro.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |

UDT: UDP-based Data Transfer Library - version 4

11 |

Yunhong Gu

12 | 13 |

Welcome to the UDT4 SDK documentation.

14 |

UDT is a high performance data transfer protocol - UDP-based data transfer protocol. It was designed for 15 | data intensive applications over high speed wide area networks, to overcome the efficiency and fairness problems of TCP. 16 | As its name indicates, UDT is built on top of UDP and it provides both reliable data streaming and messaging services.

17 |

Visit http://udt.sf.net for most recent news on UDT.

18 | 19 |

Check out most current UDT release at SourceForge or from CVS.

20 | 21 |

export CVS_RSH=ssh
22 | cvs -d:pserver:anonymous@udt.cvs.sourceforge.net:/cvsroot/udt login
23 | [NOTE: when prompt for password, press the RETURN/ENTER key]
24 | cvs -d:pserver:anonymous@udt.cvs.sourceforge.net:/cvsroot/udt co UDT4

25 | 26 |

In this documentation:

27 | 34 |

 

35 | 36 | 37 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/listen.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

listen

13 |

The listen method enables a server UDT entity to wait for clients to connect.

14 | 15 |
int list(
16 |   UDTSOCKET u
17 |   int backlog
18 | );
19 | 20 |
Parameters
21 |
22 |
u
23 |
[in] Descriptor identifying the server socket.
24 |
backlog
25 |
[in] Maximum number of pending connections.
26 |
27 | 28 |
Return Value
29 |

If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 |
Error NameError CodeComment
ECONNSOCK5002u is already connected.
EINVSOCK5004u is an invalid socket.
EUNBOUNDSOCK5005u is not bound.
ERDVNOSERV5007u is in rendezvous mode.
58 | 59 |
Description
60 |

The listen method lets a UDT socket enter listening state. The socket must call bind before a listen call. In addition, if the 61 | socket is enable for rendezvous mode, neither listen nor accept can be used on the socket. A UDT socket can call listen more than once, 62 | in which case only the first call is effective, while all subsequent calls will be ignored if the socket is already in listening state.

63 | 64 |
See Also
65 |

bind, accpet, connect

66 |

 

67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/make.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 13 | 14 | 15 | 16 |

Installation Guide

17 |

The UDT library is distributed with source code, example applications, and documentation. Currently the source code can be compiled on both Linux and Windows system.

18 | 19 |

Here is the content of the distribution:

20 | 21 |

./src: UDT source code
22 | ./app: Example applications
23 | ./doc: UDT documentation
24 | ./win: Visual C++ project files for Windows version of UDT

25 | 26 |

The library is in the original source code format without any installation tools, so installation is simply a make command. To make the C++ source code on different platform, the user 27 | needs to explicitly tell make the current operating system and hardware architecture with the "-e" option (except for Windows).

28 |

The available operating system options are: LINUX, BSD, and OSX.
The available options for hardware architecture are: IA32, IA64, POWERPC, and AMD64.

29 | 30 |

The command is in the format:

31 | 32 |

make -e os=XXX arch=YYY

33 | 34 |

where XXX and YYY are one of the options above. Note that it is case sensitive. There is a default value for Linux on the IA32 architecture, so if UDT is compiled on it, simply use 35 | make. 36 |

37 | 38 |

On Windows, use the Visual Studio .Net project files at ./win directory. It requires Visual C++ 7.0 or above to compile. Windows XP or above is also required under the default setting. 39 |

If other Windows compilers are used, you may need to create 40 | your own Makefile or project files. In particular, if you use Visual C++ 6.0 or your system is Windows 2000 or certain embeded Windows systems, please define LEGACY_WIN32 in your Makefile or project files. You may also need to download Windows platform SDK in order to get the <wspiapi.h> header file.

41 |

After a successful make, you can begin to use the UDT library. The (only) header file udt.h and the library libudt.a (depending on the target system, libudt.so, libudt.dylib, and udt.dll 42 | may be available) are located in ./src directory.

43 | Proper environment configuration should be set up before using UDT library. For example, if using libudt.so, the library path environment variable must be updated as: 44 |

45 | 46 |

47 | export LD_LIBRARY_PATH=[location of libudt.so, e.g., ../src]:$LD_LIBRARY_PATH 48 |

49 |

50 |

On Windows, copy udt.dll to the proper directory.

51 |

 

52 | 53 | 54 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/peername.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

getpeername

13 |

The getpeername method retrieves the address informtion of the peer side of a connected UDT socket.

14 | 15 |
int getpeername(
16 |   UDTSOCKET u,
17 |   struct sockaddr* name,
18 |   int* namelen
19 | );
20 | 21 |
Parameters
22 |
23 |
u
24 |
[in] Descriptor identifying a connected socket.
25 |
name
26 |
[out] The structure to store the address of the peer.
27 |
addrlen
28 |
[in, out] pointer to the size of the name structure.
29 |
30 | 31 |
Return Value
32 |

On success, getlasterror returns 0 and the peer address information is stored in name; otherwise it returns UDT::ERROR and the specific error information can be 33 | retrieved using getlasterror.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
Error NameError CodeComment
ENOCONN2002u is not connected.
EINVPARAM5003Invalid parameters.
EINVSOCK5004u is an invailid UDT socket.
57 | 58 |
Description
59 |

The getpeername retrieves the address of the peer side associated to the connection. The UDT socket must be connected at the time when this method is called. The 60 | namelen must provide the leangth of the name parameter, which should be enough to hold the address information. On return, namelen contains the length of the result.

61 | 62 |
See Also
63 |

listen, connect, accept

64 |

 

65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/recv.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

recv

13 |

The recv method reads certain amount of data into a local memory buffer.

14 | 15 |
int recv(
16 |   UDTSOCKET u,
17 |   char* buf,
18 |   int len,
19 |   int flags
20 | );
21 | 22 |
Parameters
23 |
24 |
u
25 |
[in] Descriptor identifying a connected socket.
26 |
buf
27 |
[out] The buffer used to store incoming data.
28 |
len
29 |
[in] Length of the buffer.
30 |
flags
31 |
[in] Ignored. For compatibility only.
32 |
33 | 34 |
Return Value
35 |

On success, recv returns the actual size of received data. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror. If UDT_RCVTIMEO is set to a positive value, zero will be returned if no data is received before the timer expires.

37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 |
Error NameError CodeComment
ECONNLOST2001connection has been broken and no data left in receiver buffer.
ENOCONN2002u is not connected.
EINVSOCK5004u is not an valid socket.
EDGRAMILL5010cannot use recv in SOCK_DGRAM mode.
EASYNCRCV6002u is non-blocking (UDT_RCVSYN = false) but no data is available.
ETIMEOUT6003Timeout on UDT_RCVTIMEO .
75 | 76 |
Description
77 |

The recv method reads certain amount of data from the protocol buffer. If there is not enough data in the buffer, recv only reads the available data 78 | in the protocol buffer and returns the actual size of data received. However, recv will never read more data than the buffer size indicates by len.

79 |

In blocking mode (default), recv waits until there is some data received into the receiver buffer. In non-blocking mode, recv returns immediately and 80 | returns error if no data available.

81 |

If UDT_RCVTIMEO is set and the socket is in blocking mode, recv only waits a limited time specified by UDT_RCVTIMEO option. If there is still no data available when 82 | the timer expires, error will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.

83 | 84 |
See Also
85 |

send, sendfile, recvfile

86 |

 

87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/recvfile.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

recvfile

13 |

The recvfile method reads certain amount of data into a local file.

14 | 15 |
int64_t recvfile(
16 |   UDTSOCKET u,
17 |   fstream& ofs,
18 |   int64_t& offset,
19 |   int64_t size,
20 |   int block = 366000
21 | );
22 | 23 |
Parameters
24 |
25 |
u
26 |
[in] Descriptor identifying a connected socket.
27 |
ofs
28 |
[in] C++ fstream descriptor for the file to store incoming data.
29 |
offset
30 |
[in, out] The offset position from where the data is written into the file; after the call returns, this value records the new offset of the write position.
31 |
size
32 |
[in] The total size to be received.
33 |
block
34 |
[in] Optional. The size of every data block for file IO.
35 |
36 | 37 |
Return Value
38 |

On success, recvfile returns the actual size of received data. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 |
Error NameError CodeComment
ECONNLOST2001connection has been broken and no data left in receiver buffer.
ENOCONN2002u is not connected.
EFILE4000File or disk system errors.
EINVSOCK5004u is not an valid socket.
EDGRAMILL5010cannot use recvfile in SOCK_DGRAM mode.
73 | 74 |
Description
75 |

The recvfile method reads certain amount of data and write it into a local file. It is always in blocking mode and neither UDT_RCVSYN nor UDT_RCVTIMEO affects this method. The actual size of data to expect must be known before calling recvfile, otherwise deadlock may occur due to insufficient incoming data.

76 |
See Also
77 |

send, sendfile, recv

78 |

 

79 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/recvmsg.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

recvmsg

13 |

The recvmsg method receives a valid message.

14 | 15 |
int recvmsg(
16 |   UDTSOCKET u,
17 |   char* msg,
18 |   int len
19 | );
20 | 21 |
Parameters
22 |
23 |
u
24 |
[in] Descriptor identifying a connected socket.
25 |
msg
26 |
[out] The buffer used to store incoming message.
27 |
len
28 |
[in] Length of the buffer.
29 |
30 | 31 |
Return Value
32 |

On success, recvmsg returns the actual size of received message. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror. If UDT_RCVTIMEO is set to a positive value, zero will be returned if no message is received before the timer expires.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 |
Error NameError CodeComment
ECONNLOST2001connection has been broken and no data left in receiver buffer.
ENOCONN2002u is not connected.
EINVSOCK5004u is not an valid socket.
ESTREAMILL5009cannot use recvmsg in SOCK_STREAM mode.
EASYNCRCV6002u is non-blocking (UDT_RCVSYN = false) but no message is available.
ETIMEOUT6003Timeout on UDT_RCVTIMEO .
72 | 73 |
Description
74 |

The recvmsg method reads a message from the protocol buffer. The UDT socket must be in SOCK_DGRAM mode in order to send or receive messages. Message is the minimum 75 | data unit in this situation. Each recvmsg will read no more than one message, even if the message is smaller than the size of buf and there 76 | are more messages available. On the other hand, if the buf is not enough to hold the first message, only part of the message will be copied into the buffer, 77 | but the message will still be discarded after this recvmsg call.

78 |

In blocking mode (default), recvmsg waits until there is a valid message received into the receiver buffer. In non-blocking mode, 79 | recvmsg returns immediately and returns error if no message available.

80 |

If UDT_RCVTIMEO is set and the socket is in blocking mode, recvmsg only waits a limited time specified by UDT_RCVTIMEO option. If there is still 81 | no message available when the timer expires, error will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.

82 | 83 |
See Also
84 |

send, recv, sendmsg

85 |

 

86 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/reference.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |

UDT Reference

11 |

This section describes in detail the UDT API, including:

12 | 13 | 19 |

 

20 | 21 | 22 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/select.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 12 | 13 | 14 | 15 |
 UDT Reference: Functions
16 | 17 |

select

18 |

The select method queries one or more groups of UDT sockets.

19 |

Note: select is deprecated. Please use epoll instead, which is far more efficienct.

20 |
int select(
21 |   int nfds,
22 |   UDSET* readfds,
23 |   UDSET* writefds,
24 |   UDSET* exceptfds,
25 |   const struct timeval* timeout
26 | );
27 | 28 |
Parameters
29 |
30 |
nfds
31 |
[in] Ignored. For compatibility only.
32 |
readfds
33 |
[in, out] Optional pointer to a set of sockets to be checked for readability.
34 |
writefds
35 |
[in, out] Optional pointer to a set of sockets to be checked for writability.
36 |
exceptfds
37 |
[in, out] Ignored. For compatibility only.
38 |
timeout
39 |
[in] The future time when this call should be timeout.
40 |
41 | 42 |
Return Value
43 |

If any of the read or write query is positive, select returns the number of UDT sockets that are read for read/write. If no socket is ready before timeout, zero is 44 | returned. If there is any error, UDT::ERROR is returned and the specific error information can be retrieved using getlasterror. The readfds and/or 45 | writefds will be updated to contain the ready sockets only.

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
Error NameError CodeComment
EINVPARAM5003All three socket sets are empty or at least one of the socket is invalid.
60 | 61 |
Description
62 |

The UDSET is a structure to store the UDT socket descriptors. If should only be processed with the following macros.

63 |
64 |
UD_CLR(u, *set)
65 |
Removes the descriptor u from set.
66 |
UD_ISSET(u, *set)
67 |
Nonzero if u is a member of set; otherwise zero.
68 |
UD_SET(u, *set)
69 |
Add descriptor u to set.
70 |
UD_ZERO(*set)
71 |
Initialize set to an empty set.
72 |
73 | 74 |

The UDT descriptors sets originaly contains the sockets whose status is to be queried. When select returns, the descriptors sets only contain the sockets that are 75 | ready for IO. UD_ISSET can be used to check which one is ready.

76 |

readfds is used to detect if any socket in this set is available for reading (recv, recvmsg), for accepting a new connection (accept), or the associated connection is broken. 77 | writefds is used to detect if any socket in this set has available buffer for sending (send, sendmsg). Currently exceptfds is not used.

78 | 79 |
Example
80 |

The following example shows how to check if a UDT socket is available for recv.

81 | 82 |
83 |

84 | UDTSOCKET u;
85 | ...
86 |
87 | timeval tv;
88 | UDSET readfds;
89 |
90 | tv.tv_sec = 1;
91 | tv.tv_usec = 0;
92 |
93 | UD_ZERO(&readfds);
94 | UD_SET(u, &readfds);
95 |
96 | int res = UDT::select(0, &readfds, NULL, NULL, &tv);
97 |
98 | if ((res != UDT::ERROR) && (UD_ISSET(u, &readfds)))
99 |    // read data from u.
100 | else
101 |    // timeout or error
102 |

103 |
104 | 105 | 106 |
See Also
107 |

selectEx, epoll

108 |

 

109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/selectex.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 12 | 13 | 14 | 15 |
 UDT Reference: Functions
16 | 17 |

selectEx

18 |

The selectEx method queries a group of of UDT sockets for IO status.

19 |

Note: selectEx is deprecated. Please use epoll instead, which is far more efficienct.

20 |
int selectEx(
21 |   std::vector<UDTSOCKET> fds,
22 |   std::vector<UDTSOCKET>* readfds,
23 |   std::vector<UDTSOCKET>* writefds,
24 |   std::vector<UDTSOCKET>* exceptfds,
25 |   const int64_t msTimeOut
26 | );
27 | 28 |
Parameters
29 |
30 |
fds
31 |
[in] the group of UDT socket descriptors to be queried, in a C++ vector.
32 |
readfds
33 |
[out] Optional pointer to a set of sockets that are ready for recv.
34 |
writefds
35 |
[out] Optional pointer to a set of sockets that are ready for send.
36 |
exceptfds
37 |
[out] Optional pointer to a set of sockets that are closed or with a broken connection.
38 |
msTimeOut
39 |
[in] The time that this function should wait for the status change in the input groups, in milliseconds.
40 |
41 | 42 |
Return Value
43 |

If any of the read, write, or except group is not empty, selectEx returns the number of UDT sockets that are read for read/write or are broken/closed. If no socket is ready before timeout, zero is 44 | returned. If there is any error, UDT::ERROR is returned and the specific error information can be retrieved using getlasterror. The readfds,writefds and/or 45 | exceptfds will be updated to contain the ready sockets.

46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 |
Error NameError CodeComment
EINVPARAM5003All three socket sets are NULL or at least one of the socket is invalid.
60 | 61 |
Description
62 |

This function selectEx is an advanced version of select. In contrast to select, selectEx does not modify the input parameter fds, so that applications do not need to replicate or initialize it every time the function is called.

63 |

The new function only has one group of input socket descriptors. If a particular event check is not necessary, the corresponding output parameter can be set to NULL. For example, if the application does not care about if a socket is ready for send, the parameter writefds can be NULL.

64 |

Finally, selectEx specifies the absolute amount of time to wait, while select requires a clock time in the future to wait until.

65 |

Overall, selectEx is more convinient and more efficient.

66 |
67 |
See Also
68 |

select, epoll

69 |
 
70 |
71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/send.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

send

13 |

The send method sends out certain amount of data from an application buffer.

14 | 15 |
int send(
16 |   UDTSOCKET u,
17 |   const char* buf,
18 |   int len,
19 |   int flags
20 | );
21 | 22 |
Parameters
23 |
24 |
u
25 |
[in] Descriptor identifying a connected socket.
26 |
buf
27 |
[in] The buffer of data to be sent.
28 |
len
29 |
[in] Length of the buffer.
30 |
flags
31 |
[in] Ignored. For compatibility only.
32 |
33 | 34 |
Return Value
35 |

On success, send returns the actual size of data that has been sent. Otherwise UDT::ERROR is returned and specific error information can be retrieved by getlasterror. If UDT_SNDTIMEO is set to a positive value, zero will be returned if no data is sent before the timer expires.

37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
Error NameError CodeComment
ECONNLOST2001connection has been broken.
ENOCONN2002u is not connected.
EINVSOCK5004u is not an valid socket.
EDGRAMILL5010cannot use send in SOCK_DGRAM mode.
EASYNCSND6001u is non-blocking (UDT_SNDSYN = false) but buffer space is available for sending.
ETIMEOUT6003Timeout on UDT_SNDTIMEO .
EPEERERR7000The peer side has an unrecoverable error and this call has to be cancelled.
80 | 81 |
Description
82 |

The send method sends certain amount of data from the application buffer. If the the size limit of sending buffer queue is reached, 83 | send only sends a portion of the application buffer and returns the actual size of data that has been sent.

84 |

In blocking mode (default), send waits until there is some sending buffer space available. In non-blocking mode, send 85 | returns immediately and returns error if the sending queue limit is already limited.

86 |

If UDT_SNDTIMEO is set and the socket is in blocking mode, send only waits a limited time specified by UDT_SNDTIMEO option. If there is still no 87 | buffer space available when the timer expires, error will be returned. UDT_SNDTIMEO has no effect for non-blocking socket.

88 | 89 |
See Also
90 |

send, sendfile, recvfile

91 |

 

92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/sendfile.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

sendfile

13 |

The sendfile method sends out part or the whole of a local file.

14 | 15 |
int64_t sendfile(
16 |   UDTSOCKET u,
17 |   fstream& ifs,
18 |   const int64_t& offset,
19 |   const int64_t size,
20 |   const int block = 7320000
21 | );
22 | 23 |
Parameters
24 |
25 |
u
26 |
[in] Descriptor identifying a connected socket.
27 |
ifs
28 |
[in] C++ fstream descriptor for the file to read data from.
29 |
offset
30 |
[in, out] The offset position from where the data is read from the file. After the call returns, this value holds the updated read position.
31 |
size
32 |
[in] The total size to be sent.
33 |
block
34 |
[in] Optional. The size of every data block for file IO.
35 |
36 | 37 |
Return Value
38 |

On success, sendfile returns the actual size of data that has been sent. Otherwise UDT::ERROR is returned and specific error information can be retrieved by 39 | getlasterror.

40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 |
Error NameError CodeComment
ECONNLOST2001connection has been broken.
ENOCONN2002u is not connected.
EINVOP4000File or disk system errors.
EINVSOCK5004u is not an valid socket.
EDGRAMILL5010cannot use sendfile in SOCK_DGRAM mode.
EPEERERR7000The peer side has an unrecoverable error and this call has to be cancelled.
78 | 79 |
Description
80 |

The sendfile method sends certain amount of out of a local file. It is always in blocking mode an neither UDT_SNDSYN nor UDT_SNDTIMEO affects this method. However, the sendfile method has a streaming semantics same as send.

81 |

Note that sendfile does NOT nessesarily require recvfile at the peer side. Sendfile/recvfile and send/recv are orthogonal 82 | UDT methods.

83 | 84 |
See Also
85 |

send, recv, recvfile

86 |

 

87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/socket.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

socket

13 |

The socket method creates a new UDT socket.

14 | 15 |
UDTSOCKET socket(
16 |   int af,
17 |   int type,
18 |   int protocol
19 | );
20 | 21 |
Parameters
22 |
23 |
af
24 |
[in] IP Family: AF_INET or AF_INET6.
25 |
type
26 |
[in] Type of the socket: SOCK_STREAM or SOCK_DGRAM.
27 |
protocol
28 |
[in] Ignored. For compatibility only.
29 |
30 | 31 |
Return Value
32 |

If no error occurs, socket returns the new UDT socket descriptor; otherwise, it returns UDT::INVALID_SOCK and the error information can be retrieved by getlasterror.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 |
Error NameError CodeComment
EINVPARAM5003Invalid parameters.
47 | 48 |
Description
49 |

The socket methods creates a new socket. The is no limits for the number of UDT sockets in one system, as long as there is enough system 50 | resource. UDT supports both IPv4 and IPv6, which can be selected by the af parameter. On the other hand, two socket types are supports in UDT, i.e., 51 | SOCK_STREAM for data streaming and SOCK_DGRAM for messaging. Note that UDT sockets are connection oriented in all cases.

52 | 53 |
See Also
54 |

close

55 | 56 |

 

57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/sockname.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

getsockname

13 |

The getsockname method retrieves the local address associated with a UDT socket.

14 | 15 |
int getsockname(
16 |   UDTSOCKET u,
17 |   struct sockaddr* name,
18 |   int* namelen
19 | );
20 | 21 |
Parameters
22 |
23 |
u
24 |
[in] Descriptor identifying a connected socket.
25 |
name
26 |
[out] The structure to store the local address.
27 |
addrlen
28 |
[in, out] pointer to the size of the name structure.
29 |
30 | 31 |
Return Value
32 |

On success, getlasterror returns 0 and the local address information is stored in name; otherwise it returns UDT::ERROR and the specific error information can be 33 | retrieved using getlasterror.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
Error NameError CodeComment
EINVPARAM5003Invalid parameters.
EINVSOCK5004u is an invailid UDT socket.
EUNBOUNDSOCK5005u is not bound to a local address yet.
57 | 58 |
Description
59 |

The getsockname retrieves the local address associated with the socket. The UDT socket must be bound explicitly (via bind) or implicitly (via 60 | connect), otherwise this method will fail because there is no meaningful address bound to the socket.

61 |

If getsockname is called after an explicit bind, but before connect, the IP address returned will be exactly the IP address that is used for bind and it may be 0.0.0.0 if ADDR_ANY is used. If getsockname is called after connect, the IP address returned will be the address that the peer socket sees. In the case when there is a proxy (e.g., NAT), the IP address returned will be the translated address by the proxy, but not a local address. If there is no proxy, the IP address returned will be a local address. In either case, the port number is local (i.e, not the translated proxy port).

62 |

Because UDP is connection-less, using getsockname on a UDP port will almost always return 0.0.0.0 as IP address (unless it is bound to an explicit IP) . As a connection oriented protocol, UDT will return a meaningful IP address by getsockname if there is no proxy translation exist.

63 |

UDT has no multihoming support yet. When there are multiple local addresses and more than one of them can be routed to the destination address, UDT may not behave properly due to the multi-path effect. In this case, the UDT socket must be explicitly bound to one of the local addresses.

64 |
See Also
65 |

listen, bind, connect

66 |

 

67 | 68 | 69 | 70 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/startup.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

startup

13 |

The startup method initializes the UDT library.

14 | 15 |
int startup(
16 | );
17 | 18 |
Parameters
19 |
20 |
None.
21 |
22 | 23 |
Return Value
24 |

If success, 0 is returned; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

25 |

In the current version, this method always succeed.

26 |
Description
27 |

The startup method initializes the UDT library. In particular, it starts the garbage collection thread. This method must be called before any other UDT calls. Failure to do so may cause memory leak.

28 |

If startup is called multiple times in one application, only the first one is effective, while the rest will do nothing.

29 |
See Also
30 |

cleanup

31 |

 

32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-cc.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 12 | 13 | 14 | 15 |
 UDT Tutorial
16 | 17 |

User-defined Congestion Control Algorithm

18 |

You can add your own congestion control algorithm into UDT. It is as simple as to define several callback functions that will be triggered on certain events, e.g, when an ACK is 19 | received.

20 | 21 |

All the congestion control callback functions are collected in a C++ class CCC. You have to inherit this class to define your own congestion control algorithm. That is, UDT/CCC uses an 22 | object-oriented design. CCC in defined in ccc.h, which you have to include in your files in order to enable this feature.

23 | 24 |

The CCC class contains two control variables: m_dPktSndPeriod, and m_dCWndSize. m_dPktSndPeriod is a double float number representing the packet sending period (as to be used in rate 25 | control), in microseconds. m_dCWndSize is a double float number representing the size of the congestion window (cwnd), in number of packets. The congestion control algorithm will need to 26 | update at least one of them. For example, for pure window based approach, m_dPktSndPeriod should always be zero.

27 | 28 |

The fast way to learn CCC is to use the examples in ./app/cc.h. The file cc.h also includes many more advanced control mechanisms that your control classes can be derived from. For 29 | example, if you are designing a new TCP variant, you can implement the new control class directly from CTCP.

30 | 31 |

Here we demonstrate the usage of UDT/CCC by writing a reliable UDP blast control mechanism.

32 | 33 |
34 | class CUDPBlast: public CCC
35 | {
36 | public:
37 |   CUDPBlast() {m_dCWndSize = 83333.0;}
38 |
39 | public:
40 |   void setRate(int mbps)
41 |   {
42 |     m_dPktSndPeriod = (m_iMSS * 8.0) / mbps;
43 |   }
44 | };
45 | 46 |

In this example, CUDPBlast inherits from the base class CCC. In the constructor, it sets the congestion window size to a large value so that it will not affect the packet sending. (This 47 | is pure rate based method to blast UDP packets.) The method SetRate() can be used to set a fixed packet sending rate at any time.

48 | 49 |

The application can use setsockopt/getsockopt to assign this control class to a UDT instance, and/or set its parameters.

50 | 51 |
52 | UDT::setsockopt(usock, 0, UDT_CC, new CCCFactory<CUDPBlast> 53 | 54 | , sizeof(CCCFactory<CUDPBlast> 55 | )); 56 |
57 | 58 | 59 |

The above code assigns the CUDPBlast control algorthm to a UDT socket usock. Note that CCCFactory is using the Abstract Factory design pattern.

60 | 61 |

To set a specific data sending rate, the application needs to obtain a handle to the concrete CCC class instance used by the UDT socket usock.

62 | 63 |
64 | CUDPBlast* cchandle = NULL;
65 | int temp;
66 | UDT::getsockopt(usock, 0, UDT_CC, &cchandle, &temp); 67 |
68 | 69 |

The application can then call the method of setRate() to set a 500Mbps data rate.

70 | 71 |
72 | if (NULL != cchandle)
73 |   cchandle->setRate(500); 74 |
75 | 76 |

The UDT/CCC can be used to implement most control mechanims, including but not limited to rate-based approaches, TCP variants (e.g., TCP, Scalable, HighSpeed, BiC, Vegas, FAST), and 77 | group-based approaches (e.g., GTP, CM).

78 | 79 |
Note
80 |

1. Do NOT call regular UDT API inside CCC or its derived classes. Unknown error could happen.

81 | 82 |

2. CCCFactory<...> is a C++ template class. You do not need to derive any classes from it.

83 | 84 |

3. UDT will not release the CCCFactory<...> instance. The application should release it, at anywhere after the setsockopt() call.

85 | 86 |
See Also
87 |

Congestion Control Class

88 | 89 |

 

90 | 91 | 92 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-config.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Configure UDT Options

13 |

Options of UDT are read and set through getsockopt and setsockopt methods. Before modifying any option, bear in mind that it is NOT required that you modify the default options. If the application has sound performance with the default options, just use the default configurations.

14 | 15 |

UDT_MSS is used to configure the packet size. In most situations, the optimal UDT packet size is the network MTU size. The default value is 1500 bytes. A UDT connection will choose the 16 | smaller value of the MSS between the two peer sides. For example, if you want to set 9000-byte MSS, you have to set this option at both sides, and one of the value has to be exactly equal to 17 | 9000, and the other must not be less than 9000.

18 | 19 |

UDT uses a different semantics of synchronization mode from traditional sockets. It can set the sending and receiving synchronization independently, which allows more flexibility. 20 | However, UDT does not allow non-blocking operation on connection setup and close. The sychronization mode of sending and receiving can be set on UDT_SNDSYN and UDT_RCVSYN, respectively.

21 | 22 |

The UDT buffer size is (UDT_SNDBUF and UDT_RCVBUF) used to limit the size of temporary storage of sending/receiving data. The buffer size is only a limit and memory is allocated upon necessary. Generally, larger 23 | buffer (but not so large that the physical memory is used up) is better. For good performance the the buffer sizes for both sides should be at least Bandwidth*RTT.

24 | 25 |

UDT uses UDP as the data channel, so the UDP buffer size affects the performance. Again, a larger value is generally better, but the effects become smaller and disappear as the buffer 26 | size increases. Generally, the sending buffer size can be a small value, because it does not limit the packet sending much but a large value may increase the end-to-end delay.

27 | 28 |

UDT_FC is actually an internal parameter and you should set it to not less than UDT_RCVBUF/UDT_MSS. The default value is relatively large, therefore unless you set a very large 29 | receiver buffer, you do not need to change this option.

30 | 31 |

UDT_LINGER is similar to the SO_LINGER option on the regular sockets. It allows the UDT socket continue to sent out data in the sending buffer when close is called.

32 | 33 |

UDT_RENDEZVOUS is used to enable rendezvous connection setup. When rendezvous mode is enabled, a UDT socket cannot call listen or accept; instead, in order to set up a rendezvous 34 | connection, both the peer sides must call connect at approximately the same time. This is useful in traversing a firewall.

35 | 36 |

UDT_SNDTIMEO and UDT_RCVTIMEO are similar to SO_SNDTIMEO and SO_RCVTIMEO, respectively. They are used to set a timeout value for packet sending and receiving.

37 |

UDT_REUSEADDR allows applications to decide whether to share a UDP port with other UDT connections. By default this option is true, which means all UDT connections that are bind to 0 will try to reuse any existing UDP socket. In addition, multiple UDT connections can bind to the same port number other than 0. If UDT_REUSEADDR is set to false, an exclusive UDP port will be assign to this UDT socket. There are a few situations when UDT_REUSEADDR should be set to false. First, two UDT sockets cannot listen on the same port number, so either the second UDT socket is explicitly bound to a different port, or UDT_REUSEADDR is set to false for this UDT socket. Second, a UDT socket bound to a specific port number cannot connect to the other UDT socket bound to the same port on the same IP address.

38 |

Example: read current UDT settings

39 |
40 | UDTSOCKET u;
41 |
42 | ...
43 |
44 | bool block;
45 | int size = sizeof(bool); 46 |
47 | UDT::getsockopt(u, UDT_SNDSYN, 0, &block, &size); 48 |
49 | 50 |

Example: modify UDT settings

51 |
52 | UDTSOCKET u;
53 |
54 | ...
55 |
56 | bool block = false;
57 |
58 | UDT::setsockopt(u, UDT_SNDSYN, 0, &block, sizeof(bool)); 59 |
60 | 61 | 62 |
See Also
63 |

getsockopt, setsockopt

64 | 65 | 66 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-data.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Transfering Data using UDT

13 |

This section describes using UDT to transfer data in streaming mode. This is exactly the same as using traditional BSD socket.

14 | 15 |

In streaming mode, neither a send or a recv call can guarantee that all data are sent or received in one call, because there is no boundary information in the data stream. Application 16 | should use loops for both sending and receiving.

17 | 18 |

Example: send a data block (buf, size) using UDT.

19 |
20 | int ssize = 0;
21 | int ss;
22 | while (ssize < size)
23 | {
24 |   if (UDT::ERROR == (ss = UDT::send(usock, buf + ssize, size - ssize, 0)))
25 |   {
26 |     cout << "send:" << UDT::getlasterror().getErrorMessage() << endl;
27 |     break;
28 |   }
29 |
30 |   ssize += ss;
31 | } 32 |
33 | 34 |

Similarily, to receive data stream, the following example code can be used.

35 |

Example: receive "size" of data into buffer "buf"

36 |
37 | int rsize = 0;
38 | int rs;
39 | while (rsize < size)
40 | {
41 |   if (UDT::ERROR == (rs = UDT::recv(usock, buf + rsize, size - rsize, 0)))
42 |   
43 |     cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl;
44 |     break;
45 |   }
46 |
47 |   rsize += rs;
48 | } 49 |
50 | 51 |
Blocking vs. Non-blocking
52 |

UDT supports both blocking and non-blocking mode. The above example demonstrated the blocking mode. In non-blocking mode, UDT::send and UDT::recv will return immediately if there is 53 | no buffer available. Usually, non-blocking calls are used together with accept.

54 |

UDT also supports timed blocking IO with UDT_SNDTIMEO and UDT_RCVTIMEO. This is in the middle between complete blocking and complete non-blocking calls. Timed IO will block the 55 | sending or receiving call for a limited period. This is sometimes useful if the application does not know if and when the peer side will send a message.

56 | 57 |

 

58 | 59 | 60 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-error.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Error Handling

13 |

All UDT API will return an error upon a failed operation. Particularly, UDT defines UDT::INVALID_SOCK and UDT::ERROR as error returned values. Application should check the return 14 | value against these two constants (several routine return false as error value).

15 | 16 |

On error, getlasterror can be used to retrieve the error information. In fact, the function returns the latest error occurred in the thread where the function is called. getlasterror returns an ERRORINFO structure, it contains both the error code and special text error message. Two helper functions of getErrorCode and getErrorMessage can be used to read these 17 | information.

18 |

The UDT error information is thread local (that is, an error in another thread will not affect the error information in the current thread). The returned value is a reference to the UDT internal error structure.

19 |

Note that a successful call will NOT clear the error. Therefore, applications should use the return value of a UDT API to check the result of a UDT call. getlasterror only provides detailed information when necessary. However, application can use getlasterror().clear() to clear the previously logged error if needed.

20 |

Example: check UDT::bind error.

21 |
22 | sockaddr_in my_addr;
23 | my_addr.sin_family = AF_INET;
24 | my_addr.sin_port = htons(21); //invalid port number
25 | my_addr.sin_addr.s_addr = INADDR_ANY;
26 | memset(&(my_addr.sin_zero), '\0', 8);
27 |
28 | UDTSOCKET serv = UDT::socket(AF_INET, SOCK_STREAM, 0);
29 | if (UDT::ERROR == UDT::bind(serv, (sockaddr*)&my_addr, sizeof(my_addr)))
30 | {
31 |   cout << "bind: " << UDT::getlasterror().getErrorMessage();
32 |   // further action may depends on UDT::getlasterror().getErrorCode().
33 |   // system level error can be accessed through "errno"
34 |   return 0;
35 | } 36 |
37 | 38 |

In the example above, the output will be:

39 |
40 | error message: Couldn't set up network connection: Permission denied. 41 |
42 | 43 |

The UDT error code only reflects the operation error of the UDT socket level. Applications can still read the system level error (e.g., errno in Linux, GetLastError in Windows) to read 44 | more specific error information. However, the error message obtained by getErrorMessage contains information of both the UDT level error and the system level error.

45 | 46 |

 

47 | 48 | 49 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-file.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

File Transfer using UDT

13 |

While you can always use regular UDT::send and UDT::recv to transfer a file, UDT provides a more convinient and optimized way for file transfer. An application can use UDT::sendfile 14 | and UDT::recvfile directly. In addition, file transfer IO API and regular data IO API are orthogonal. E.g., the data stream sent out by UDT::sendfile does not necessarily require 15 | UDT::recvfile to accept.

16 | 17 |

The sendfile and recvfile methods are blocking call and are not affected by UDT_SNDSYN, UDT_RCVSYN, UDT_SBDTIMEO, or UDT_RCVTIMEO. They always complete the call with the specified 18 | size parameter for sending or receiving unless errors occur.

19 | 20 |

UDT uses C++ fstream for file IO.

21 | 22 |

Example: send a file using UDT.

23 |
24 | UDTSOCKET fhandle;
25 | ...
26 |
27 | ifstream& ifs("largefile.dat");
28 | ifs.seekg(0, ios::end);
29 | streampos size = ifs.tellg();
30 | ifs.seekg(0, ios::beg);
31 |
32 | if (UDT::ERROR == UDT::sendfile(fhandle, ifs, 0, size))
33 | {
34 |   cout << "sendfile: " << UDT::getlasterror().getErrorMessage();
35 |   return 0;
36 | } 37 |
38 | 39 |

Example: Receive data into a file.

40 |
41 | UDTSOCKET recver;
42 | ...
43 |
44 | ofstream& ofs("largefile.dat");
45 |
46 | if (UDT::ERROR == UDT::recvfile(fhandle, ofs, 0, size))
47 | {
48 |   cout << "recvfile: " << UDT::getlasterror().getErrorMessage();
49 |   return 0;
50 | } 51 |
52 | 53 |

 

54 | 55 | 56 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-firewall.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Firewall Traversing with UDT

13 |

While UDT was originally written for extremely high speed data transfer, there are many other potential benefits from this reliable UDP-based library. One particular usage is to setup 14 | reliable connections between machines behind firewalls. To meet this requirement, UDT has added the rendezvous connection setup support.

15 | 16 |

Traditional BSD socket setup process requires explicit server side and client side. To punch NAT firewalls, a common method is to use the SO_REUSEADDR socket option to open two sockets 17 | bound to the same port, one listens and the other connects. UDT provides the more convenient rendezvous connection setup, in which there is no server or client, and two users can connect to 18 | each other directly.

19 | 20 |

With UDT, all sockets within one process can be bound to the same UDP port (but at most one listening socket on the same port is allowed). This is also helpful for system administrators to open a specific UDP port for all UDT traffic.

21 | 22 |

Example: Rendezvous connection setup. (Note that there is no need to set UDT_REUSEADDR here because it is true by default.)

23 |
24 | UDTSOCKET u;
25 | ...
26 |
27 | bool rendezvous = true;
28 | UDT::setsockopt(u, 0, UDT_RENDEZVOUS, &rendezvous, sizeof(bool));
29 | UDT::bind(u, &known_addr, sizeof(known_addr));
30 | UDT::connect(u, &peer_addr, sizeof(peer_addr)); 31 |
32 | 33 |

In addition, UDT also allows to bind on an existing UDP socket. This is useful in two situations. First, sometimes the application must send packet to a name server in order to obtain its address (for example, this is true when behind an NAT firewall). Users may create a UDP socket and send some UDP packets to the name server to obtain the binding address. Then the UDP socket can be used directly for UDT (see bind) so that the application does not need to close the UDP socket and open a new UDT socket on the same address again.

34 |

Second, some firewalls working on local system may change the port mapping or close the "hole" is the punching UDP socket is closed, thus a new UDT socket on the same address will not be able to traverse the firewall. In this situation, binding the UDT socket on the existing UDP socket is not only convenient but necessary.

35 |

 

36 | 37 | 38 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-hello.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Hello World!

13 |

In this section we will introduce the simplest UDT program that can transfer data in high performance.

14 | 15 |

This simple "Hello World!" example includes a server program and a client program just like any socket programming tutorial. These are the simpler version of the appserver and appclient 16 | examples in ./app directory.

17 | 18 |

To compile, use gcc -o server server.cpp -I 19 | 20 | -L 21 | 22 | -ludt -lstdc++ -lpthread. For more details, please refer to the Makefile in ./app directory.

23 | 24 |

UDT server example

25 | 26 |
27 | #include <arpa/inet.h>
28 | #include <udt.h>
29 | #include <iostream.h>
30 |
31 | using namespace std;
32 |
33 | int main()
34 | {
35 | UDTSOCKET serv = UDT::socket(AF_INET, SOCK_STREAM, 0);
36 |
37 | sockaddr_in my_addr;
38 | my_addr.sin_family = AF_INET;
39 | my_addr.sin_port = htons(9000);
40 | my_addr.sin_addr.s_addr = INADDR_ANY;
41 | memset(&(my_addr.sin_zero), '\0', 8);
42 |
43 | if (UDT::ERROR == UDT::bind(serv, (sockaddr*)&my_addr, sizeof(my_addr)))
44 | {
45 |   cout << "bind: " << UDT::getlasterror().getErrorMessage();
46 |   return 0;
47 | }
48 |
49 | UDT::listen(serv, 10);
50 |
51 | int namelen;
52 | sockaddr_in their_addr;
53 |
54 | UDTSOCKET recver = UDT::accept(serv, (sockaddr*)&their_addr, &namelen);
55 |
56 | char ip[16];
57 | cout << "new connection: " << inet_ntoa(their_addr.sin_addr) << ":" << ntohs(their_addr.sin_port) << endl;
58 |
59 | char data[100];
60 |
61 | if (UDT::ERROR == UDT::recv(recver, data, 100, 0))
62 | {
63 |   cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl;
64 |   return 0;
65 | }
66 |
67 | cout << data << endl;
68 |
69 | UDT::close(recver);
70 | UDT::close(serv);
71 |
72 | return 1;
73 | } 74 |
75 | 76 |

This simple server tries to bind itself at port 9000. If succeed, it listens at port 9000 and accepts a client and then reads a string.

77 |

UDT client example

78 |
79 | #include <iostream>
80 | #include <udt.h>
81 | #include <arpa/inet.h>
82 |
83 | using namespace std;
84 | using namespace UDT;
85 |
86 | int main()
87 | {
88 | UDTSOCKET client = UDT::socket(AF_INET, SOCK_STREAM, 0);
89 |
90 | sockaddr_in serv_addr;
91 | serv_addr.sin_family = AF_INET;
92 | serv_addr.sin_port = htons(9000);
93 | inet_pton(AF_INET, "127.0.0.1", &serv_addr.sin_addr);
94 |
95 | memset(&(serv_addr.sin_zero), '\0', 8);
96 |
97 | // connect to the server, implict bind
98 | if (UDT::ERROR == UDT::connect(client, (sockaddr*)&serv_addr, sizeof(serv_addr)))
99 | {
100 |   cout << "connect: " << UDT::getlasterror().getErrorMessage();
101 |   return 0;
102 | }
103 |
104 | char* hello = "hello world!\n";
105 | if (UDT::ERROR == UDT::send(client, hello, strlen(hello) + 1, 0))
106 | {
107 |   cout << "send: " << UDT::getlasterror().getErrorMessage();
108 |   return 0;
109 | }
110 |
111 | UDT::close(client);
112 |
113 | return 1;
114 | } 115 |
116 | 117 |

The client side connects to the local address (127.0.0.1) at port 9000, and sends a "hello world!" message.

118 |

Note that in this "Hello World!" example the UDT::send and UDT::recv routines should use a loop to check return value. However, since the string length is very small and can be hold in one packet, we omit the loop part in order to give a simpler example.

119 | 120 |

 

121 | 122 | 123 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-intro.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Introduction to Programming with UDT

13 |

The prerequisite knowledge for using UDT is sound experience on C++ and socket programing. This is enough to use UDT in distributed applications. If you are familiar with computer 14 | networking, you may find UDT more powerful.

15 | 16 |

UDT is a C++ library, which has almost identical routines as the BSD socket APIs. Using UDT in a C++ program is very straightforward. In fact, you may easily modify your existing code 17 | from TCP to UDT.

18 | 19 |

Because of the similarity between UDT API and BSD socket API, UDT defines its own namespace UDT to differentiate the UDT APIs from the regular socket APIs. A qualifier of UDT:: should be 20 | put before the UDT socket call. UDTSOCKET is a data type to describe a UDT socket. For a complete UDT structures and constant definitions, please see Reference:UDT Structures. For a complete 21 | description of UDT socket APIs, please see Reference:UDT Functions.

22 | 23 |

For those socket APIs that does not involve with a socket descriptor, e.g., inet_pton, they are not wrapped by UDT API, and the applications should continue to use the original functions. 24 | For those socket APIs or options not appropriate to UDT, e.g., certain TCP options, they are simply not available in UDT API.

25 | 26 |

For example, using BSD socket, you write:

27 | 28 |
29 | int s = socket(AF_INET, SOCK_STREAM, 0); 30 |
31 | 32 |

Its counterpart in UDT is like this:

33 | 34 |
35 | UDTSOCKET u = UDT::socket(AF_INET, SOCK_STREAM, 0); 36 |
37 | 38 |

UDT API is thread-safe. UDT sockets can be shared by multiple threads and UDT API on the same socket can be made concurrently. However, because of its application level nature, UDT 39 | sockets cannot be shared among processes. That is, a UDT socket created in one process cannot be used in another process.

40 | 41 |

If you use a programming language other than C++, you may need to write certain wrapper for the UDT C++ API. For example, you may use "extern C" to wrap UDT API in C; there are also 42 | ways to call C++ API in Java.

43 | 44 |

To use UDT in a C++ application:

45 | 46 |

Header

47 |

#include <udt.h>

48 | 49 |

Library (depending on platforms)

50 |

libudt.so
libudt.a
udt.dll
udt.lib
udt.dylib

51 | 52 |

Namespace

53 |

UDT

54 | 55 |

 

56 | 57 | 58 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-msg.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Messaging with Partial Reliability

13 |

When a UDT socket is created as SOCK_DGRAM type, UDT will send and receive data as messages. The boundary of the message is preserved and the message is delivered 14 | as a whole unit. Sending or receving messages do not need a loop; a message will be either completely delivered or not delivered at all. However, at the receiver 15 | side, if the user buffer is shorter than the message length, only part of the message will be copied into the user buffer while the message will still be 16 | discarded.

17 | 18 |

Example: send and receive messages using UDT.

19 |
20 | UDTSOCKET u = UDT::socket(AF_INET, SOCK_DGRAM, 0);
21 |
22 | char data[1024];
23 | int size = 1024;
24 |
25 | int ssize = UDT::sendmsg(client, data, size, -1, false);
26 |
27 | int rsize = UDT::recvmsg(u, data, size); 28 |
29 | 30 |

At the sender side, applications can specify two options for every message. The first is the life time (TTL) of a message. The default value is infinite, which 31 | means that the message will always be delivered. If the value is a postive one, UDT will discard the message if it cannot be delivered by the life time expires. 32 | The second is the order of the message. An in-order message means that this message will not be delivered unless all the messages prior to it are either delivered 33 | or discarded.

34 | 35 |

Synchronization modes (blocking vs. non-blocking) are also applied to SOCK_DGRAM sockets, so does not other UDT mechanisms including but limited to congestion 36 | control, flow control, and connection maintainence. Finally, note that UDT SOCK_DGRAM socket is also connection oriented. A UDT connection can only be set up 37 | between the same socket types.

38 | 39 |

 

40 | 41 | 42 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/t-udt3.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |
 UDT Tutorial
11 | 12 |

Transition from UDT3

13 |

If you have never used UDT before, please skip this page.

14 | 15 |

If you are familiar with previous versions of UDT, in particular UDT3, please noted that we have several major changes in UDT4 and you may need to modify your existing code a little 16 | in order to use UDT4. In addition, different versions of UDT do not communicate with each other.

17 | 18 |

UDT4 have made the following improvements

19 |
    20 |
  • UDT4 uses a UDP multiplexer for multiple UDT sockets, therefore it is possible (and by default) all UDT sockets in one process will share one UDP port. This scheme makes it easier 21 | for firewall traversing.
  • 22 |
  • UDT4 has a new buffer management module that enables all UDT sockets in one process can share protocol buffer. The goodness it brings is the much less memory usage for multiple 23 | UDT connections compared to previous versions.
  • 24 |
  • UDT4 can automatically resize its buffer in order to reduce memory usage while providing maximum throughput.
  • 25 |
  • Because of the new memory management scheme, overlapped IO has been removed from UDT4. If your existing code uses overlapped IO, you need to modify it to use regular IO. This is 26 | the only change needed for exiting code to move from UDT3 to UDT4.
  • 27 |
  • UDT4 has an enhanced code based and some bug fixes.
  • 28 |
29 | 30 |

Finally, UDT4 does not provide the NS-2 simulation code (nor any support to previous versions of simulation code) any more.

31 | 32 |

 

33 | 34 | 35 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/trace.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UDT Reference 6 | 7 | 8 | 9 | 10 |
 UDT Reference: Functions
11 | 12 |

perfmon

13 |

The perfmon method retrieves the internal protocol parameters and performance trace.

14 | 15 |
int perfmon(
16 |   UDTSOCKET u,
17 |   TRACEINFO* perf,
18 |   bool clear = true
19 | );
20 | 21 |
Parameters
22 |
23 |
u
24 |
[in] Descriptor identifying a UDT entity.
25 |
trace
26 |
[out] Pointer to the TRACEINFO structure to store the performance information.
27 |
clear
28 |
[in] Flag that indicates if the local traces should be cleared and counts should be restarted.
29 |
30 | 31 |
Return Value
32 |

If success, 0 is returned and trace information is written into trace; otherwise, UDT::ERROR is returned and specific error information can be retrieved by getlasterror.

34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 |
Error NameError CodeComment
ECONNLOST2001connection is broken.
EINVSOCK5004u is an invalid socket.
EUNBOUNDSOCK5005u is not connected.
57 | 58 |
Description
59 |

The perfmon method reads the performance data since the last time perfmon is executed, or since the connection is started. The result in written into a TRACEINFO structure.

60 |

There are three kinds of performance information that can be read by applications: the total counts since the connection is started, the periodical counts since last time the counts are cleared, and instant parameter values.

61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/treeview.css: -------------------------------------------------------------------------------- 1 | /* jSh - Stylesheet for JavaScript TreeView documentation */ 2 | 3 | pre { margin-left:10px; } 4 | h1,h2,h3,h4,h5,h6,pre,tt { color:#0000CC; } 5 | a.an { text-decoration:none; } 6 | a:active { color:#CC0000; text-decoration:none; } 7 | a:link { color:#CC0000; text-decoration:underline; } 8 | a:visited { color:#990066; text-decoration:underline; } 9 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/tutorial.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Introduction 6 | 7 | 8 | 9 | 10 |

UDT Tutorial

11 |

This tutorial is a quick guide on how to program with UDT and includes explanations and examples. You can learn the basics of UDT programming in this tutorial. This tutorial supposes that 12 | you are familiar with socket programming. The example codes can be found in the ./app directory of the software release, which can be compiled and run directly.

13 | 14 |

In this section:

15 | 16 | 28 | 29 |

 

30 | 31 | 32 | -------------------------------------------------------------------------------- /udt/udt4/doc/doc/udtdoc.css: -------------------------------------------------------------------------------- 1 | /* CSS Document */ 2 | 3 | body { 4 | background-color: #FFFFFF; 5 | font-family: Verdana, Arial, Helvetica, sans-serif; 6 | font-size: 12px; 7 | line-height: 18px; 8 | color: #333333; 9 | } 10 | 11 | .note1 { 12 | font-family: Verdana, Arial, Helvetica, sans-serif; 13 | font-size: 12px; 14 | font-style: normal; 15 | line-height: normal; 16 | color: #333333; 17 | padding: 0px 0px 10px 10px; 18 | margin-top: 0; 19 | margin-bottom: 0; 20 | list-style-image: none; 21 | } 22 | 23 | .ref_head { 24 | font-family: Verdana, Arial, Helvetica, sans-serif; 25 | font-size: 12px; 26 | font-style: italic; 27 | font-weight: bold; 28 | background-color: #99CCFF; 29 | padding: 3px 3px 3px 3px; 30 | } 31 | 32 | .code { 33 | font-family: "Courier New", Courier, monospace; 34 | font-size: 10px; 35 | line-height: 12px; 36 | background-color: #C0C0C0; 37 | padding: 5px 5px 5px 5px; 38 | } 39 | 40 | .func_name { 41 | font-family: Verdana, Arial, Helvetica, sans-serif; 42 | font-size: 18px; 43 | color: #000000; 44 | } 45 | 46 | .table_headline { 47 | font-family: Verdana, Arial, Helvetica, sans-serif; 48 | font-size: 12px; 49 | background-color: #C0C0C0; 50 | padding: 2px 2px 2px 2px; 51 | } 52 | -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_book.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_book.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_down.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_down.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_end.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_end.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_endm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_endm.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_endp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_endp.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_leaf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_leaf.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_line.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_line.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_link.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_link.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_list.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_list.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_listm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_listm.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_listp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_listp.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_open.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_open.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_space.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_space.gif -------------------------------------------------------------------------------- /udt/udt4/doc/hlp/ix_up.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/hlp/ix_up.gif -------------------------------------------------------------------------------- /udt/udt4/doc/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | UDT Manual 5 | 6 | 7 | 8 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | <body> 65 | 66 | <p>This page uses frames, but your browser doesn't support them.</p> 67 | 68 | </body> 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /udt/udt4/doc/main.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/serverlessunicorn/ServerlessNetworkingClients/a3be34d3b3791a95ae041f3c6aca37e1bf8c6b02/udt/udt4/doc/main.htm -------------------------------------------------------------------------------- /udt/udt4/src/Makefile: -------------------------------------------------------------------------------- 1 | C++ = g++ 2 | 3 | ifndef os 4 | os = LINUX 5 | endif 6 | 7 | ifndef arch 8 | arch = IA32 9 | endif 10 | 11 | CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing -fvisibility=hidden 12 | 13 | ifeq ($(arch), IA32) 14 | CCFLAGS += -DIA32 15 | endif 16 | 17 | ifeq ($(arch), POWERPC) 18 | CCFLAGS += -mcpu=powerpc 19 | endif 20 | 21 | ifeq ($(arch), SPARC) 22 | CCFLAGS += -DSPARC 23 | endif 24 | 25 | ifeq ($(arch), IA64) 26 | CCFLAGS += -DIA64 27 | endif 28 | 29 | ifeq ($(arch), AMD64) 30 | CCFLAGS += -DAMD64 31 | endif 32 | 33 | OBJS = api.o buffer.o cache.o ccc.o channel.o common.o core.o epoll.o list.o md5.o packet.o queue.o window.o 34 | DIR = $(shell pwd) 35 | 36 | all: libudt.so libudt.a udt 37 | 38 | %.o: %.cpp %.h udt.h 39 | $(C++) $(CCFLAGS) $< -c 40 | 41 | libudt.so: $(OBJS) 42 | ifneq ($(os), OSX) 43 | $(C++) -shared -o $@ $^ 44 | else 45 | $(C++) -dynamiclib -o libudt.dylib -lstdc++ -lpthread -lm $^ 46 | endif 47 | 48 | libudt.a: $(OBJS) 49 | ar -rcs $@ $^ 50 | 51 | udt: 52 | cp udt.h udt 53 | 54 | clean: 55 | rm -f *.o *.so *.dylib *.a udt 56 | 57 | install: 58 | export LD_LIBRARY_PATH=$(DIR):$$LD_LIBRARY_PATH 59 | -------------------------------------------------------------------------------- /udt/udt4/src/cache.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright (c) 2001 - 2009, The Board of Trustees of the University of Illinois. 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are 7 | met: 8 | 9 | * Redistributions of source code must retain the above 10 | copyright notice, this list of conditions and the 11 | following disclaimer. 12 | 13 | * Redistributions in binary form must reproduce the 14 | above copyright notice, this list of conditions 15 | and the following disclaimer in the documentation 16 | and/or other materials provided with the distribution. 17 | 18 | * Neither the name of the University of Illinois 19 | nor the names of its contributors may be used to 20 | endorse or promote products derived from this 21 | software without specific prior written permission. 22 | 23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 24 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 25 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 26 | PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 27 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 28 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 29 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 30 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 31 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 32 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 33 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 | *****************************************************************************/ 35 | 36 | /***************************************************************************** 37 | written by 38 | Yunhong Gu, last updated 05/05/2009 39 | *****************************************************************************/ 40 | 41 | #ifdef WIN32 42 | #include 43 | #include 44 | #ifdef LEGACY_WIN32 45 | #include 46 | #endif 47 | #endif 48 | 49 | #include 50 | #include "cache.h" 51 | #include "core.h" 52 | 53 | using namespace std; 54 | 55 | CInfoBlock& CInfoBlock::operator=(const CInfoBlock& obj) 56 | { 57 | std::copy(obj.m_piIP, obj.m_piIP + 3, m_piIP); 58 | m_iIPversion = obj.m_iIPversion; 59 | m_ullTimeStamp = obj.m_ullTimeStamp; 60 | m_iRTT = obj.m_iRTT; 61 | m_iBandwidth = obj.m_iBandwidth; 62 | m_iLossRate = obj.m_iLossRate; 63 | m_iReorderDistance = obj.m_iReorderDistance; 64 | m_dInterval = obj.m_dInterval; 65 | m_dCWnd = obj.m_dCWnd; 66 | 67 | return *this; 68 | } 69 | 70 | bool CInfoBlock::operator==(const CInfoBlock& obj) 71 | { 72 | if (m_iIPversion != obj.m_iIPversion) 73 | return false; 74 | 75 | else if (m_iIPversion == AF_INET) 76 | return (m_piIP[0] == obj.m_piIP[0]); 77 | 78 | for (int i = 0; i < 4; ++ i) 79 | { 80 | if (m_piIP[i] != obj.m_piIP[i]) 81 | return false; 82 | } 83 | 84 | return true; 85 | } 86 | 87 | CInfoBlock* CInfoBlock::clone() 88 | { 89 | CInfoBlock* obj = new CInfoBlock; 90 | 91 | std::copy(m_piIP, m_piIP + 3, obj->m_piIP); 92 | obj->m_iIPversion = m_iIPversion; 93 | obj->m_ullTimeStamp = m_ullTimeStamp; 94 | obj->m_iRTT = m_iRTT; 95 | obj->m_iBandwidth = m_iBandwidth; 96 | obj->m_iLossRate = m_iLossRate; 97 | obj->m_iReorderDistance = m_iReorderDistance; 98 | obj->m_dInterval = m_dInterval; 99 | obj->m_dCWnd = m_dCWnd; 100 | 101 | return obj; 102 | } 103 | 104 | int CInfoBlock::getKey() 105 | { 106 | if (m_iIPversion == AF_INET) 107 | return m_piIP[0]; 108 | 109 | return m_piIP[0] + m_piIP[1] + m_piIP[2] + m_piIP[3]; 110 | } 111 | 112 | void CInfoBlock::convert(const sockaddr* addr, int ver, uint32_t ip[]) 113 | { 114 | if (ver == AF_INET) 115 | { 116 | ip[0] = ((sockaddr_in*)addr)->sin_addr.s_addr; 117 | ip[1] = ip[2] = ip[3] = 0; 118 | } 119 | else 120 | { 121 | memcpy((char*)ip, (char*)((sockaddr_in6*)addr)->sin6_addr.s6_addr, 16); 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /udt/udt4/src/md5.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. 3 | 4 | This software is provided 'as-is', without any express or implied 5 | warranty. In no event will the authors be held liable for any damages 6 | arising from the use of this software. 7 | 8 | Permission is granted to anyone to use this software for any purpose, 9 | including commercial applications, and to alter it and redistribute it 10 | freely, subject to the following restrictions: 11 | 12 | 1. The origin of this software must not be misrepresented; you must not 13 | claim that you wrote the original software. If you use this software 14 | in a product, an acknowledgment in the product documentation would be 15 | appreciated but is not required. 16 | 2. Altered source versions must be plainly marked as such, and must not be 17 | misrepresented as being the original software. 18 | 3. This notice may not be removed or altered from any source distribution. 19 | 20 | L. Peter Deutsch 21 | ghost@aladdin.com 22 | 23 | */ 24 | /* $Id: md5.h,v 1.2 2007/12/24 05:58:37 lilyco Exp $ */ 25 | /* 26 | Independent implementation of MD5 (RFC 1321). 27 | 28 | This code implements the MD5 Algorithm defined in RFC 1321, whose 29 | text is available at 30 | http://www.ietf.org/rfc/rfc1321.txt 31 | The code is derived from the text of the RFC, including the test suite 32 | (section A.5) but excluding the rest of Appendix A. It does not include 33 | any code or documentation that is identified in the RFC as being 34 | copyrighted. 35 | 36 | The original and principal author of md5.h is L. Peter Deutsch 37 | . Other authors are noted in the change history 38 | that follows (in reverse chronological order): 39 | 40 | 2002-04-13 lpd Removed support for non-ANSI compilers; removed 41 | references to Ghostscript; clarified derivation from RFC 1321; 42 | now handles byte order either statically or dynamically. 43 | 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. 44 | 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); 45 | added conditionalization for C++ compilation from Martin 46 | Purschke . 47 | 1999-05-03 lpd Original version. 48 | */ 49 | 50 | #ifndef md5_INCLUDED 51 | # define md5_INCLUDED 52 | 53 | /* 54 | * This package supports both compile-time and run-time determination of CPU 55 | * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be 56 | * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is 57 | * defined as non-zero, the code will be compiled to run only on big-endian 58 | * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to 59 | * run on either big- or little-endian CPUs, but will run slightly less 60 | * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. 61 | */ 62 | 63 | typedef unsigned char md5_byte_t; /* 8-bit byte */ 64 | typedef unsigned int md5_word_t; /* 32-bit word */ 65 | 66 | /* Define the state of the MD5 Algorithm. */ 67 | typedef struct md5_state_s { 68 | md5_word_t count[2]; /* message length in bits, lsw first */ 69 | md5_word_t abcd[4]; /* digest buffer */ 70 | md5_byte_t buf[64]; /* accumulate block */ 71 | } md5_state_t; 72 | 73 | #ifdef __cplusplus 74 | extern "C" 75 | { 76 | #endif 77 | 78 | /* Initialize the algorithm. */ 79 | void md5_init(md5_state_t *pms); 80 | 81 | /* Append a string to the message. */ 82 | void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); 83 | 84 | /* Finish the message and return the digest. */ 85 | void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); 86 | 87 | #ifdef __cplusplus 88 | } /* end extern "C" */ 89 | #endif 90 | 91 | #endif /* md5_INCLUDED */ 92 | -------------------------------------------------------------------------------- /udt/udt4/win/appclient.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | 17 | 34 | 36 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 | 68 | 73 | 90 | 92 | 102 | 104 | 106 | 108 | 110 | 112 | 114 | 116 | 118 | 120 | 122 | 123 | 124 | 125 | 126 | 127 | 130 | 132 | 133 | 134 | 137 | 139 | 140 | 142 | 143 | 144 | 147 | 148 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /udt/udt4/win/appserver.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | 17 | 34 | 36 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 65 | 67 | 68 | 73 | 90 | 92 | 102 | 104 | 106 | 108 | 110 | 112 | 114 | 116 | 118 | 120 | 122 | 123 | 124 | 125 | 126 | 127 | 130 | 132 | 133 | 134 | 137 | 139 | 140 | 142 | 143 | 144 | 147 | 148 | 150 | 151 | 152 | 153 | 154 | 155 | -------------------------------------------------------------------------------- /udt/udt4/win/recvfile.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | 17 | 33 | 35 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 67 | 72 | 86 | 88 | 98 | 100 | 102 | 104 | 106 | 108 | 110 | 112 | 114 | 116 | 118 | 119 | 120 | 121 | 122 | 123 | 126 | 128 | 129 | 130 | 133 | 135 | 136 | 137 | 140 | 141 | 143 | 144 | 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /udt/udt4/win/sendfile.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 10 | 11 | 12 | 17 | 33 | 35 | 46 | 48 | 50 | 52 | 54 | 56 | 58 | 60 | 62 | 64 | 66 | 67 | 72 | 87 | 89 | 99 | 101 | 103 | 105 | 107 | 109 | 111 | 113 | 115 | 117 | 119 | 120 | 121 | 122 | 123 | 124 | 127 | 129 | 130 | 131 | 134 | 136 | 137 | 138 | 141 | 142 | 144 | 145 | 146 | 147 | 148 | 149 | -------------------------------------------------------------------------------- /udt/udt4/win/test.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 11 | 12 | 13 | 19 | 31 | 33 | 43 | 45 | 47 | 49 | 51 | 53 | 55 | 57 | 59 | 61 | 63 | 64 | 70 | 79 | 81 | 92 | 94 | 96 | 98 | 100 | 102 | 104 | 106 | 108 | 110 | 112 | 113 | 114 | 115 | 116 | 117 | 121 | 123 | 125 | 129 | 130 | 131 | 132 | 136 | 137 | 141 | 142 | 143 | 144 | 145 | 146 | -------------------------------------------------------------------------------- /udt/udt4/win/udt.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 8.00 2 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "appclient", "appclient.vcproj", "{4C848417-B545-468B-AA0C-44EE73BC7B9B}" 3 | ProjectSection(ProjectDependencies) = postProject 4 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C} = {D84D100A-7C21-4CCB-B16E-0FB37137C16C} 5 | EndProjectSection 6 | EndProject 7 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "appserver", "appserver.vcproj", "{1F726B88-8807-4E99-9982-CCE33198BEE8}" 8 | ProjectSection(ProjectDependencies) = postProject 9 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C} = {D84D100A-7C21-4CCB-B16E-0FB37137C16C} 10 | EndProjectSection 11 | EndProject 12 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "recvfile", "recvfile.vcproj", "{3D73B2C7-9C2A-4901-9714-03FFB9367644}" 13 | ProjectSection(ProjectDependencies) = postProject 14 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C} = {D84D100A-7C21-4CCB-B16E-0FB37137C16C} 15 | EndProjectSection 16 | EndProject 17 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sendfile", "sendfile.vcproj", "{88AFBB12-0392-4210-A89C-E932BE3AB2E0}" 18 | ProjectSection(ProjectDependencies) = postProject 19 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C} = {D84D100A-7C21-4CCB-B16E-0FB37137C16C} 20 | EndProjectSection 21 | EndProject 22 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "udt", "udt.vcproj", "{D84D100A-7C21-4CCB-B16E-0FB37137C16C}" 23 | ProjectSection(ProjectDependencies) = postProject 24 | EndProjectSection 25 | EndProject 26 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test", "test.vcproj", "{C70F9A98-ECFF-4DC7-895D-0E41936BD1BA}" 27 | ProjectSection(ProjectDependencies) = postProject 28 | EndProjectSection 29 | EndProject 30 | Global 31 | GlobalSection(SolutionConfiguration) = preSolution 32 | Debug = Debug 33 | Release = Release 34 | EndGlobalSection 35 | GlobalSection(ProjectConfiguration) = postSolution 36 | {4C848417-B545-468B-AA0C-44EE73BC7B9B}.Debug.ActiveCfg = Debug|Win32 37 | {4C848417-B545-468B-AA0C-44EE73BC7B9B}.Debug.Build.0 = Debug|Win32 38 | {4C848417-B545-468B-AA0C-44EE73BC7B9B}.Release.ActiveCfg = Release|Win32 39 | {4C848417-B545-468B-AA0C-44EE73BC7B9B}.Release.Build.0 = Release|Win32 40 | {1F726B88-8807-4E99-9982-CCE33198BEE8}.Debug.ActiveCfg = Debug|Win32 41 | {1F726B88-8807-4E99-9982-CCE33198BEE8}.Debug.Build.0 = Debug|Win32 42 | {1F726B88-8807-4E99-9982-CCE33198BEE8}.Release.ActiveCfg = Release|Win32 43 | {1F726B88-8807-4E99-9982-CCE33198BEE8}.Release.Build.0 = Release|Win32 44 | {3D73B2C7-9C2A-4901-9714-03FFB9367644}.Debug.ActiveCfg = Debug|Win32 45 | {3D73B2C7-9C2A-4901-9714-03FFB9367644}.Debug.Build.0 = Debug|Win32 46 | {3D73B2C7-9C2A-4901-9714-03FFB9367644}.Release.ActiveCfg = Release|Win32 47 | {3D73B2C7-9C2A-4901-9714-03FFB9367644}.Release.Build.0 = Release|Win32 48 | {88AFBB12-0392-4210-A89C-E932BE3AB2E0}.Debug.ActiveCfg = Debug|Win32 49 | {88AFBB12-0392-4210-A89C-E932BE3AB2E0}.Debug.Build.0 = Debug|Win32 50 | {88AFBB12-0392-4210-A89C-E932BE3AB2E0}.Release.ActiveCfg = Release|Win32 51 | {88AFBB12-0392-4210-A89C-E932BE3AB2E0}.Release.Build.0 = Release|Win32 52 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Debug.ActiveCfg = Debug|Win32 53 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Debug.Build.0 = Debug|Win32 54 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release.ActiveCfg = Release|Win32 55 | {D84D100A-7C21-4CCB-B16E-0FB37137C16C}.Release.Build.0 = Release|Win32 56 | {C70F9A98-ECFF-4DC7-895D-0E41936BD1BA}.Debug.ActiveCfg = Debug|Win32 57 | {C70F9A98-ECFF-4DC7-895D-0E41936BD1BA}.Debug.Build.0 = Debug|Win32 58 | {C70F9A98-ECFF-4DC7-895D-0E41936BD1BA}.Release.ActiveCfg = Release|Win32 59 | {C70F9A98-ECFF-4DC7-895D-0E41936BD1BA}.Release.Build.0 = Release|Win32 60 | EndGlobalSection 61 | GlobalSection(ExtensibilityGlobals) = postSolution 62 | EndGlobalSection 63 | GlobalSection(ExtensibilityAddIns) = postSolution 64 | EndGlobalSection 65 | EndGlobal 66 | --------------------------------------------------------------------------------