├── src ├── version ├── version.sh ├── udr_util.h ├── Makefile ├── udr_threads.h ├── udr_options.h ├── udr_log.cpp ├── cc.h └── udr_util.cpp ├── tests ├── fixtures │ └── fixture1.txt ├── requirements.txt ├── test_simple.py └── conftest.py ├── udt ├── doc │ ├── main.htm │ ├── hlp │ │ ├── ix_end.gif │ │ ├── ix_up.gif │ │ ├── ix_book.gif │ │ ├── ix_down.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 │ ├── doc │ │ ├── treeview.css │ │ ├── header.htm │ │ ├── footer.htm │ │ ├── reference.htm │ │ ├── udtdoc.css │ │ ├── startup.htm │ │ ├── tutorial.htm │ │ ├── error.htm │ │ ├── cleanup.htm │ │ ├── intro.htm │ │ ├── t-udt3.htm │ │ ├── t-file.htm │ │ ├── copy.htm │ │ ├── t-msg.htm │ │ ├── socket.htm │ │ ├── close.htm │ │ ├── trace.htm │ │ ├── listen.htm │ │ ├── peername.htm │ │ ├── t-data.htm │ │ ├── t-firewall.htm │ │ ├── t-intro.htm │ │ ├── make.htm │ │ ├── t-error.htm │ │ ├── recvfile.htm │ │ ├── accept.htm │ │ ├── sendfile.htm │ │ ├── recv.htm │ │ ├── recvmsg.htm │ │ ├── send.htm │ │ ├── function.htm │ │ ├── sockname.htm │ │ ├── selectex.htm │ │ ├── t-hello.htm │ │ ├── connect.htm │ │ ├── t-cc.htm │ │ ├── bind.htm │ │ └── select.htm │ └── index.htm ├── tuner │ ├── settings.txt │ ├── tune.sh │ ├── Makefile │ ├── README.md │ ├── cc.h │ ├── recvfile.cpp │ └── appserver.cpp ├── Makefile ├── ssl │ ├── Makefile │ ├── tls_common.h │ └── epoll.cpp ├── app │ ├── udcat_common.h │ ├── Makefile │ ├── cc.h │ ├── udcat_common.cpp │ ├── recvfile.cpp │ ├── udcat_client.cpp │ ├── appserver.cpp │ └── udcat_server.cpp ├── RELEASE_NOTES.txt ├── src │ ├── Makefile │ ├── md5.h │ └── cache.cpp ├── README.txt ├── LICENSE.txt └── win │ ├── udt.sln │ ├── recvfile.vcproj │ ├── sendfile.vcproj │ ├── test.vcproj │ ├── appclient.vcproj │ └── appserver.vcproj ├── Makefile ├── server ├── udrd.conf.example └── daemon.py ├── .travis.yml ├── LICENSE.txt ├── .gitignore └── .travis └── setup_ssh.sh /src/version: -------------------------------------------------------------------------------- 1 | v0.9.4-11-g7885528 2 | -------------------------------------------------------------------------------- /tests/fixtures/fixture1.txt: -------------------------------------------------------------------------------- 1 | test1 2 | -------------------------------------------------------------------------------- /tests/requirements.txt: -------------------------------------------------------------------------------- 1 | pytest==2.9.1 2 | -------------------------------------------------------------------------------- /udt/doc/main.htm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/main.htm -------------------------------------------------------------------------------- /udt/doc/hlp/ix_end.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_end.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_up.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_up.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_book.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_book.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_down.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_down.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_endm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_endm.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_endp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_endp.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_leaf.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_leaf.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_line.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_line.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_link.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_link.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_list.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_list.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_listm.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_listm.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_listp.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_listp.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_open.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_open.gif -------------------------------------------------------------------------------- /udt/doc/hlp/ix_space.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/martinetd/UDR/HEAD/udt/doc/hlp/ix_space.gif -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | DIRS = udt src 2 | TARGETS = all clean 3 | 4 | $(TARGETS): %: $(patsubst %, %.%, $(DIRS)) 5 | 6 | $(foreach TGT, $(TARGETS), $(patsubst %, %.$(TGT), $(DIRS))): 7 | $(MAKE) -C $(subst ., , $@) -------------------------------------------------------------------------------- /udt/tuner/settings.txt: -------------------------------------------------------------------------------- 1 | /etc/sysctl.conf,/etc/sysctl.conf,0 134217728 2097152 8900,0 134217728 2097152 8900 0 2 | /etc/sysctl.conf,/etc/sysctl.conf,1 134217728 2097152 8900,1 134217728 2097152 8900 10000 3 | -------------------------------------------------------------------------------- /udt/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/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 | -------------------------------------------------------------------------------- /src/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -d ../.git ]; then git describe --tags --long > version ; fi; 3 | 4 | version=`cat version` 5 | 6 | printf "#ifndef VERSION_H\n#define VERSION_H\n" > version.h 7 | #printf "extern const char * version = \"%s" "$version" >> version.h 8 | printf "static const char * version = \"%s" "$version" >> version.h 9 | printf "\";\n#endif" >> version.h 10 | -------------------------------------------------------------------------------- /udt/doc/doc/header.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Untitled Document 6 | 7 | 8 | 9 |
10 | 11 | 12 | -------------------------------------------------------------------------------- /udt/ssl/Makefile: -------------------------------------------------------------------------------- 1 | LFLAGS = -I../src -L../src -lssl -lcrypto -ludt -lstdc++ -lpthread 2 | CC = g++ 3 | 4 | all: tls_client tls_server 5 | 6 | tls_common.o: tls_common.cpp tls_common.h e_os.h 7 | $(CC) tls_common.cpp -c $(LFLAGS) 8 | 9 | tls: tls_client tls_server 10 | 11 | tls_client: tls_common.o tls_client.cpp 12 | $(CC) $^ -o $@ $(LFLAGS) 13 | 14 | tls_server: tls_common.o tls_server.cpp 15 | $(CC) $^ -o $@ $(LFLAGS) 16 | 17 | -------------------------------------------------------------------------------- /server/udrd.conf.example: -------------------------------------------------------------------------------- 1 | # Example configuration for UDR server 2 | # Shows all of the options, all have defaults (see README) and do not have to be specified 3 | address = 127.0.0.1 4 | server port = 9000 5 | start port = 9000 6 | end port = 9100 7 | log file = /tmp/udr.log 8 | pid file = /tmp/udr-example.pid 9 | log level = INFO 10 | udr = /home/ubuntu/udr/src/udr 11 | rsyncd conf = /tmp/rsyncd.conf 12 | uid = rsyncuser 13 | gid = rsyncuser -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: "3.6" 4 | 5 | sudo: true 6 | 7 | compiler: 8 | - clang 9 | - gcc 10 | 11 | install: 12 | - .travis/setup_ssh.sh 13 | - sudo apt-get update -qq 14 | - sudo apt-get install -qq openssh-client openssh-server 15 | - cd ./udt 16 | - make 17 | - cd ../src 18 | - make 19 | - cd .. 20 | 21 | before_script: 22 | - pip install -r tests/requirements.txt 23 | 24 | script: "py.test -vv tests" 25 | -------------------------------------------------------------------------------- /udt/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 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2012 Laboratory for Advanced Computing at the University of Chicago 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. -------------------------------------------------------------------------------- /tests/test_simple.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | test_simple.py 4 | ---------------------------------- 5 | 6 | Simple test for UDR, test executable runs and help message 7 | """ 8 | 9 | from conftest import raise_for_error 10 | from os import path 11 | 12 | 13 | def test_usage(udr): 14 | assert b'usage: udr' in udr().stderr.read() 15 | 16 | 17 | def test_simple_transfer(udr, fixture_dir, default_args): 18 | inpath = path.join(fixture_dir, 'fixture1.txt') 19 | outpath = '/tmp/tixture1_out.txt' 20 | args = default_args + [inpath, '127.0.0.1:'+outpath] 21 | assert udr(args).wait() == 0 22 | 23 | with open(inpath, 'r') as f_in: 24 | with open(outpath, 'r') as f_out: 25 | assert f_in.read() == f_out.read() 26 | -------------------------------------------------------------------------------- /udt/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/app/udcat_common.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of . 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | // this should be maxline size 20 | #define BUF_SIZE 100000 21 | 22 | void* recvdata(void*); 23 | 24 | void* senddata(void*); 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | 6 | # Compiled Dynamic libraries 7 | *.so 8 | *.dylib 9 | 10 | # Compiled Static libraries 11 | *.lai 12 | *.la 13 | *.a 14 | 15 | # The UDR binary and other files 16 | src/udr 17 | src/version.h 18 | *.udr_key 19 | udt/app/appclient 20 | udt/app/appserver 21 | udt/app/recvfile 22 | udt/app/sendfile 23 | udt/app/test 24 | udt/src/udt 25 | udt/app/udcat_client 26 | udt/app/udcat_server 27 | 28 | #server 29 | *.pyc 30 | server/rsyncd.conf 31 | server/udrd.conf 32 | server/udr.log 33 | server/motd.txt 34 | server/rsynclog 35 | server/.venv 36 | server/.venv2.4 37 | server/.venv2.6 38 | 39 | # Emacs files 40 | *~ 41 | 42 | # Vim files 43 | *.swp 44 | 45 | # Python 46 | *.cache 47 | __pycache__/ 48 | *.py[cod] 49 | .Python 50 | env/ 51 | venv/ 52 | .venv/ 53 | build/ 54 | develop-eggs/ 55 | dist/ 56 | downloads/ 57 | eggs/ 58 | lib/ 59 | lib64/ 60 | parts/ 61 | sdist/ 62 | var/ 63 | *.egg-info/ 64 | .installed.cfg 65 | *.egg 66 | 67 | # Misc 68 | *.log 69 | -------------------------------------------------------------------------------- /udt/tuner/tune.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # example: 3 | # ./tune.sh 127.0.0.1 lacadmin /home/lacadmin/udr_crypto/udt/tuner/appserver /home/lacadmin/udr_crypto/udt/src 4 | 5 | port=9000 6 | 7 | host=$1 8 | remote_user=$2 9 | server_command=$3 10 | remote_udt_path=$4 11 | 12 | count=0 13 | interval=60 14 | 15 | settings_file=settings.txt 16 | client=./appclient 17 | export_ld="export LD_LIBRARY_PATH=$remote_udt_path" 18 | 19 | while read line; do 20 | 21 | server_sysctl=$(echo $line|cut -f1 -d ,) 22 | client_sysctl=$(echo $line|cut -f2 -d ,) 23 | server_args=$(echo $line|cut -f3 -d ,) 24 | client_args=$(echo $line|cut -f4 -d ,) 25 | 26 | sudo sysctl -p $client_sysctl 27 | ssh $remote_user@$host "sudo sysctl -p $server_sysctl" <&- 28 | 29 | ssh $remote_user@$host "$export_ld; $server_command $port $server_args & pid=\$!;sleep $interval;kill \$pid" <&- & 30 | 31 | $client $host $port $client_args > raw_out_test$count & 32 | client_pid=$! 33 | 34 | sleep $interval 35 | kill $client_pid 36 | 37 | count=$((count+1)) 38 | done < $settings_file 39 | -------------------------------------------------------------------------------- /src/udr_util.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2012 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of UDR. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #ifndef UDR_PROCESSES_H 20 | #define UDR_PROCESSES_H 21 | 22 | pid_t fork_execvp(const char *program, char* argv[], int * ptc, int * ctp); 23 | int get_server_connection(char * host, char * port, char * udr_cmd, char * line, int line_size); 24 | 25 | #endif -------------------------------------------------------------------------------- /udt/RELEASE_NOTES.txt: -------------------------------------------------------------------------------- 1 | version 4.10 2 | 3 | added UDT_SNDDATA and UDT_RCVDATA options 4 | fixed a bug that causes unnecessary connection timeout 5 | improved epoll UDT event handling 6 | 7 | version 4.9 8 | 9 | asynchronous close 10 | asynchronous connect 11 | some bug fixes, especially on EPOLL 12 | improved cache code 13 | removed unnecessary NAK (reduced loss retransmission) 14 | receiver side error can unblock a blocked sender 15 | 16 | version 4.8 17 | 18 | fix a bug that may cause seg fault on concurrent close on the same socket 19 | add epoll support 20 | increase the listener's scalability to 100K concurrent connections 21 | fix a bug that may cause accept/select to return positively when an accepted socket is closed immediately after accept returns 22 | fix a bug that may cause connect to fail if the server closes listening socket immediately after accept returns 23 | fix recvfile fstream write status bug (e.g., when disk is full, recvfile should handle properly now) 24 | 25 | version 4.7a 26 | 27 | fix timeout bug introduced in 4.7 28 | initialize CHandShake 29 | 30 | version 4.7 31 | 32 | Fix several related bugs that can cause hang/memory leak/segmentation fault during cleanup() 33 | -------------------------------------------------------------------------------- /udt/src/Makefile: -------------------------------------------------------------------------------- 1 | C++ = g++ -g 2 | 3 | ifndef os 4 | os = LINUX 5 | endif 6 | 7 | ifndef arch 8 | arch = AMD64 9 | endif 10 | 11 | CCFLAGS = -fPIC -Wall -Wextra -D$(os) -finline-functions -O3 -fno-strict-aliasing #-msse3 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 = md5.o common.o window.o list.o buffer.o packet.o channel.o queue.o ccc.o cache.o core.o epoll.o api.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/tuner/Makefile: -------------------------------------------------------------------------------- 1 | C++ = g++ 2 | 3 | ifndef os 4 | os = LINUX 5 | endif 6 | 7 | ifndef arch 8 | arch = AMD64 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 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 | 57 | clean: 58 | rm -f *.o $(APP) 59 | 60 | install: 61 | export PATH=$(DIR):$$PATH 62 | -------------------------------------------------------------------------------- /src/Makefile: -------------------------------------------------------------------------------- 1 | C++ = g++ 2 | 3 | ifndef os 4 | os = LINUX 5 | endif 6 | 7 | ifndef arch 8 | arch = AMD64 9 | endif 10 | 11 | CCFLAGS = -Wall -D$(os) -I../udt/src -finline-functions -g 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 ../udt/src/libudt.a -lstdc++ -lpthread -lm -lssl -lcrypto 30 | 31 | ifeq ($(os), UNIX) 32 | LDFLAGS += -lsocket 33 | endif 34 | 35 | ifeq ($(os), OSX) 36 | LDFLAGS += -I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib 37 | CCFLAGS += -I/usr/local/opt/openssl/include 38 | endif 39 | 40 | ifeq ($(os), SUNOS) 41 | LDFLAGS += -lrt -lsocket 42 | endif 43 | 44 | DIR = $(shell pwd) 45 | 46 | APP = version.h udr 47 | 48 | all: $(APP) 49 | 50 | version.h: 51 | ./version.sh 52 | 53 | %.o: %.cpp 54 | $(C++) $(CCFLAGS) $< -c 55 | 56 | udr: udr.o udr_threads.o udr_util.o udr_options.o 57 | $(C++) $^ -o $@ $(LDFLAGS) 58 | 59 | clean: 60 | rm -f *.o $(APP) 61 | 62 | install: 63 | export PATH=$(DIR):$$PATH 64 | -------------------------------------------------------------------------------- /udt/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/ssl/tls_common.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of . 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #ifndef TLS_COMMON_H 20 | #define TLS_COMMON_H 21 | 22 | #include 23 | 24 | #include 25 | 26 | static BIO *bio_err = NULL; 27 | static const char rnd_seed[] = "string to make the random number generator think it has entropy"; 28 | 29 | int doit_biopair(SSL *s_ssl, UDTSOCKET recver, int is_server, int in_file, int out_file); 30 | 31 | int ctx_init(SSL_CTX **ctx); 32 | 33 | int verify_paths(SSL_CTX *ctx); 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /udt/README.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2001 - 2011, The Board of Trustees of the University of Illinois. 2 | All Rights Reserved. 3 | Copyright (c) 2011, 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 | 36 | To use UDT in your application: 37 | Read index.htm in ./doc. The documentation is in HTML format and requires your 38 | browser to support JavaScript. 39 | 40 | 41 | Questions? please post to the UDT project forum: 42 | https://sourceforge.net/projects/udt/forums 43 | -------------------------------------------------------------------------------- /.travis/setup_ssh.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Setup SSH script for Travis cloned form 4 | # https://github.com/jbardin/scp.py 5 | 6 | 7 | set -e 8 | 9 | # Sets up an SSH server 10 | rm -Rf /tmp/ssh_server 11 | mkdir /tmp/ssh_server 12 | cd /tmp/ssh_server 13 | 14 | # Server config file 15 | cat >config <<'EOF' 16 | Port 10022 17 | ListenAddress 127.0.0.1 18 | 19 | Protocol 2 20 | HostKey /tmp/ssh_server/key_rsa 21 | HostKey /tmp/ssh_server/key_dsa 22 | UsePrivilegeSeparation no 23 | 24 | # Authentication 25 | LoginGraceTime 10 26 | PermitRootLogin no 27 | StrictModes no 28 | UsePAM no 29 | 30 | RSAAuthentication yes 31 | PubkeyAuthentication yes 32 | AuthorizedKeysFile /tmp/ssh_server/client/id_rsa.pub 33 | 34 | PrintMotd yes 35 | EOF 36 | 37 | # Server keys 38 | ssh-keygen -f key_rsa -N '' -t rsa 39 | ssh-keygen -f key_dsa -N '' -t dsa 40 | 41 | # Client keys 42 | umask 077 43 | mkdir client || true 44 | ssh-keygen -f client/id_rsa -N '' -t rsa 45 | umask 022 46 | 47 | # Starts the server 48 | /usr/sbin/sshd -f config -h key_rsa -h key_dsa -p 10022 49 | 50 | # Sets up the client 51 | umask 077 52 | mkdir ~/.ssh || true 53 | cp client/id_rsa ~/.ssh/id_rsa 54 | umask 022 55 | rm -f ~/.ssh/known_hosts 56 | # ssh-keyscan is bugged, don't use it 57 | # ssh-keyscan -v -p 10022 -t rsa 127.0.0.1 >> ~/.ssh/known_hosts 58 | ssh -o StrictHostKeyChecking=no \ 59 | -o PasswordAuthentication=no \ 60 | -p 10022 127.0.0.1 exit 61 | cat ~/.ssh/known_hosts 62 | -------------------------------------------------------------------------------- /udt/app/Makefile: -------------------------------------------------------------------------------- 1 | C++ = g++ 2 | 3 | ifndef os 4 | os = LINUX 5 | endif 6 | 7 | ifndef arch 8 | arch = AMD64 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 udcat_client udcat_server 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 | udcat_server: udcat_server.o udcat_common.o 59 | $(C++) $^ -o $@ $(LDFLAGS) 60 | udcat_client: udcat_client.o udcat_common.o 61 | $(C++) $^ -o $@ $(LDFLAGS) 62 | 63 | clean: 64 | rm -f *.o $(APP) 65 | 66 | install: 67 | export PATH=$(DIR):$$PATH 68 | -------------------------------------------------------------------------------- /udt/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/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/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/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/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 | -------------------------------------------------------------------------------- /src/udr_threads.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2012 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of UDR. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #ifndef UDR_THREADS_H 20 | #define UDR_THREADS_H 21 | 22 | #include "crypto.h" 23 | #include "udr_options.h" 24 | 25 | const int max_block_size = 64*1024; //what should this be? maybe based on UDT buffer size? 26 | 27 | typedef struct timeout_mon_args{ 28 | FILE * logfile; 29 | int timeout; 30 | } timeout_mon_args; 31 | 32 | 33 | struct thread_data{ 34 | UDTSOCKET * udt_socket; 35 | int fd; 36 | int id; 37 | crypto * crypt; 38 | bool log; 39 | string logfile_dir; 40 | bool is_complete; 41 | }; 42 | 43 | void *handle_to_udt(void *threadarg); 44 | void *udt_to_handle(void *threadarg); 45 | 46 | int run_sender(UDR_Options * udr_options, unsigned char * passphrase, const char* cmd, int argc, char ** argv); 47 | int run_receiver(UDR_Options * udr_options); 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /udt/tuner/README.md: -------------------------------------------------------------------------------- 1 | UDT Tuner 2 | === 3 | 4 | This is a modification of udt/app/app(client/server) that takes cli args 5 | along with a bash script that will run the client server pair with UDT and 6 | sysctl settings. 7 | 8 | USAGE 9 | ------ 10 | Running the bash script tune.sh will read settings from the file settings.txt then as specified by cli args ssh to a remote host load a sysctl file and start the appserver with parameters from the local settings.txt. Then tune.sh loads a local sysctl file and starts the appclient. Both the server and client run for 1 minute and are then killed. The output of appclient is writting to raw_out_testN where N is the line of settings.txt being run starting from 0. 11 | 12 | ### Basic usage: 13 | ./tune.sh 127.0.0.1 lacadmin /home/lacadmin/udr_crypto/udt/tuner/appserver /home/lacadmin/udr_crypto/udt/src 14 | 15 | tune.sh will ssh to 127.0.0.1 as lacadmin then export LD_LIBRARY_PATH=/home/lacadmin/udr_crypto/udt/src then start /home/lacadmin/udr_crypto/udt/tuner/appserver 16 | 17 | ### Example settings.txt: 18 | /etc/sysctl.conf,/etc/sysctl.conf,0 134217728 2097152 8900,0 134217728 2097152 8900 0 19 | /etc/sysctl.conf,/etc/sysctl.conf,1 134217728 2097152 8900,1 134217728 2097152 8900 10000 20 | 21 | On the remote server run: 22 | sudo sysctl -p /etc/sysctl.conf 23 | Then locally run: 24 | sudo sysctl -p /etc/sysctl.conf 25 | Then remotely run: 26 | PATH_FROM_ARGS/appserver 9000 0 134217728 2097152 8900 27 | Then locally: 28 | ./appclient HOST_FROM_ARGS 9000 0 134217728 2097152 8900 0 29 | 30 | 0 means no blast congestion control. 134217728 is the UDT buffer size, 2097152 is the UDP buffer size, 8900 is the UDT MSS, and 0 is the blast rate. 31 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | conftest.py 4 | ---------------------------------- 5 | 6 | Setup for UDR pytest test suite 7 | """ 8 | 9 | from subprocess import Popen, PIPE 10 | from os.path import dirname, realpath, join 11 | from os import environ 12 | 13 | import pytest 14 | 15 | 16 | def raise_for_error(proc): 17 | """Raises a RuntimeError if :param:`proc` did not exit successfully""" 18 | 19 | proc.poll() 20 | if proc.returncode != 0: 21 | raise RuntimeError(proc.stderr.read()) 22 | 23 | 24 | @pytest.fixture(scope='session') 25 | def ssh_port(): 26 | return environ.get('UDT_SSH_PORT', '10022') 27 | 28 | 29 | @pytest.fixture(scope='session') 30 | def src_dir(): 31 | return join(dirname(dirname(realpath(__file__))), 'src') 32 | 33 | 34 | @pytest.fixture(scope='session') 35 | def udr_path(): 36 | return join(src_dir(), 'udr') 37 | 38 | 39 | @pytest.fixture(scope='session') 40 | def fixture_dir(): 41 | return join(dirname(dirname(realpath(__file__))), 'tests', 'fixtures') 42 | 43 | 44 | @pytest.fixture(scope='session') 45 | def default_args(udr_path, ssh_port): 46 | return [ 47 | '-v', 48 | '-c'+udr_path, 49 | '-P'+ssh_port, 50 | 'rsync', 51 | ] 52 | 53 | @pytest.yield_fixture 54 | def udr(udr_path, src_dir): 55 | """Returns a Popen partial function to run UDR""" 56 | 57 | # Return a partial to start the process (savinging it in closure 58 | # bound _process to clean up later) 59 | processes = [] 60 | def start_udr(args=[]): 61 | """Starts udr with arguments :param:`args`""" 62 | print(f'Running with args {args}') 63 | process = Popen([udr_path]+list(args), stdout=PIPE, stderr=PIPE) 64 | processes.append(process) 65 | return processes[-1] 66 | 67 | yield start_udr 68 | 69 | for process in processes: 70 | process.wait() 71 | -------------------------------------------------------------------------------- /udt/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/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 | 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/ssl/epoll.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of . 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | struct udt_epoll_args { 20 | int efd; 21 | int signal_fd; 22 | }; 23 | 24 | 25 | void *epoll_signal_thread(void *my_args) 26 | { 27 | struct udt_epoll_args *args = (struct udt_epoll_args*)my_args; 28 | std::set udt_read_fds; 29 | char sink[1]; 30 | int ret; 31 | 32 | while (true) { 33 | ret = UDT::epoll_wait(args->efd, &udt_read_fds, NULL, -1); 34 | if (ret < 1 || udt_read_fds.size() < 1) 35 | break; 36 | write(args->signal_fd, "", 1); 37 | } 38 | } 39 | 40 | 41 | int udt_epoll(int udt_efd, pthread_t *signal_thread) 42 | { 43 | int proxy_fd[2]; 44 | struct udt_epoll_args *args; 45 | 46 | args = (struct udt_epoll_args*)malloc(sizeof(struct udt_epoll_args)); 47 | 48 | pipe(proxy_fd); 49 | 50 | args->signal_fd = proxy_fd[1]; 51 | args->efd = udt_efd; 52 | 53 | pthread_create(signal_thread, NULL, epoll_signal_thread, (void*)args); 54 | 55 | fcntl(proxy_fd[0], F_SETFL, O_NONBLOCK); 56 | 57 | return proxy_fd[0]; 58 | } 59 | 60 | int udt_epoll_wait(int udt_efd, int signal_sink, set* udt_read_fds) 61 | { 62 | UDT::epoll_wait(udt_efd, &udt_read_fds, NULL, -1, &read_fds); 63 | read(signal_sink, sink, 1); 64 | } 65 | 66 | -------------------------------------------------------------------------------- /udt/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/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/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/tuner/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/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/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 | -------------------------------------------------------------------------------- /src/udr_options.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2012 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of UDR. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #ifndef UDR_OPTIONS_H 20 | #define UDR_OPTIONS_H 21 | #include 22 | #include 23 | #include 24 | 25 | struct UDR_Options{ 26 | // The port UDR will attempt the initial SSH connection over 27 | int ssh_port; 28 | int start_port; 29 | int end_port; 30 | int timeout; 31 | 32 | bool tflag; 33 | bool sflag; 34 | bool verbose; 35 | bool encryption; 36 | bool version_flag; 37 | bool server_connect; 38 | 39 | char udr_program_src[PATH_MAX+1]; 40 | char udr_program_dest[PATH_MAX+1]; 41 | char ssh_program[PATH_MAX+1]; 42 | char rsync_program[PATH_MAX+1]; 43 | char rsync_timeout[PATH_MAX+1]; 44 | char shell_program[PATH_MAX+1]; 45 | 46 | char key_base_filename[PATH_MAX+1]; 47 | char key_filename[PATH_MAX+1]; 48 | 49 | char host[PATH_MAX+1]; 50 | char port_num[NI_MAXSERV+1]; 51 | char username[PATH_MAX+1]; 52 | char which_process[PATH_MAX+1]; 53 | char version[PATH_MAX+1]; 54 | char server_dir[PATH_MAX+1]; 55 | char server_port[NI_MAXSERV+1]; 56 | 57 | char server_config[PATH_MAX+1]; 58 | 59 | char encryption_type[PATH_MAX+1]; 60 | 61 | char *specify_ip; 62 | 63 | uid_t rsync_uid; 64 | gid_t rsync_gid; 65 | 66 | }; 67 | 68 | void usage(); 69 | 70 | int get_udr_options(UDR_Options * options, int argc, char * argv[], int rsync_arg_idx); 71 | 72 | void get_host_username(UDR_Options * udr_options, int argc, char *argv[], int rsync_arg_idx); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /udt/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/app/udcat_common.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of . 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include "udcat_common.h" 25 | 26 | using std::cerr; 27 | using std::endl; 28 | 29 | void* recvdata(void* usocket) 30 | { 31 | UDTSOCKET recver = *(UDTSOCKET*)usocket; 32 | delete (UDTSOCKET*)usocket; 33 | 34 | char* data; 35 | int size = BUF_SIZE; 36 | data = new char[size]; 37 | 38 | while (true) { 39 | int rs; 40 | if (UDT::ERROR == (rs = UDT::recv(recver, data, size, 0))) { 41 | cerr << "recv:" << UDT::getlasterror().getErrorMessage() << endl; 42 | break; 43 | } 44 | 45 | write(fileno(stdout), data, rs); 46 | } 47 | 48 | delete [] data; 49 | 50 | UDT::close(recver); 51 | 52 | return NULL; 53 | } 54 | 55 | 56 | void* senddata(void* usocket) 57 | { 58 | UDTSOCKET client = *(UDTSOCKET*)usocket; 59 | delete (UDTSOCKET*)usocket; 60 | 61 | char* data = NULL; 62 | size_t buf_size = BUF_SIZE; 63 | int size; 64 | 65 | while ((size = getline(&data, &buf_size, stdin)) > 0) { 66 | int ssize = 0; 67 | int ss; 68 | 69 | while (ssize < size) { 70 | if (UDT::ERROR == (ss = UDT::send(client, data + ssize, size - ssize, 0))) 71 | { 72 | cerr << "send:" << UDT::getlasterror().getErrorMessage() << endl; 73 | break; 74 | } 75 | 76 | ssize += ss; 77 | } 78 | 79 | if (ssize < size) 80 | break; 81 | } 82 | 83 | free(data); 84 | 85 | UDT::close(client); 86 | 87 | return NULL; 88 | } 89 | 90 | -------------------------------------------------------------------------------- /src/udr_log.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of . 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include "udr_log.h" 32 | #include "version.h" 33 | 34 | static int log_maximum_verbosity; 35 | static bool verbose; 36 | 37 | void log_set_maximum_verbosity(int verbosity) { 38 | log_maximum_verbosity = verbosity; 39 | } 40 | 41 | void set_verbosity(bool verbosity) { 42 | verbosity = verbosity; 43 | } 44 | 45 | int verbose_print(const char *format, ...) { 46 | if (verbose) { 47 | va_list ap; 48 | char *formatted; 49 | int ret; 50 | 51 | va_start(ap, format); 52 | vasprintf(&formatted, format, ap); 53 | ret = fprintf(stderr, formatted); 54 | free(formatted); 55 | va_end(ap); 56 | return ret; 57 | } 58 | return 0; 59 | } 60 | 61 | int log_print(int verbosity, const char *format, ...) { 62 | int r = 0; 63 | va_list ap; 64 | char *formatwithtid; 65 | char *all_formatted; 66 | 67 | if (verbosity <= log_maximum_verbosity) { 68 | va_start(ap, format); 69 | asprintf(&formatwithtid, "[%s] [tid=%lu] %s", version, syscall(SYS_gettid), format); 70 | assert(formatwithtid); 71 | vasprintf(&all_formatted, formatwithtid, ap); 72 | /*r = sd_journal_printv(verbosity, formatwithtid, ap); */ 73 | openlog("udr", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL7); 74 | syslog(verbosity, all_formatted); 75 | closelog(); 76 | free(formatwithtid); 77 | free(all_formatted); 78 | va_end(ap); 79 | } 80 | 81 | return r; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /udt/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/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/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/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/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/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/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/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 | -------------------------------------------------------------------------------- /src/cc.h: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2012 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of UDR. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #include 20 | #include 21 | 22 | class CTCP: public CCC 23 | { 24 | public: 25 | void init() 26 | { 27 | m_bSlowStart = true; 28 | m_issthresh = 83333; 29 | 30 | m_dPktSndPeriod = 0.0; 31 | m_dCWndSize = 2.0; 32 | 33 | setACKInterval(2); 34 | setRTO(1000000); 35 | } 36 | 37 | virtual void onACK(const int& ack) 38 | { 39 | if (ack == m_iLastACK) 40 | { 41 | if (3 == ++ m_iDupACKCount) 42 | DupACKAction(); 43 | else if (m_iDupACKCount > 3) 44 | m_dCWndSize += 1.0; 45 | else 46 | ACKAction(); 47 | } 48 | else 49 | { 50 | if (m_iDupACKCount >= 3) 51 | m_dCWndSize = m_issthresh; 52 | 53 | m_iLastACK = ack; 54 | m_iDupACKCount = 1; 55 | 56 | ACKAction(); 57 | } 58 | } 59 | 60 | virtual void onTimeout() 61 | { 62 | m_issthresh = getPerfInfo()->pktFlightSize / 2; 63 | if (m_issthresh < 2) 64 | m_issthresh = 2; 65 | 66 | m_bSlowStart = true; 67 | m_dCWndSize = 2.0; 68 | } 69 | 70 | protected: 71 | virtual void ACKAction() 72 | { 73 | if (m_bSlowStart) 74 | { 75 | m_dCWndSize += 1.0; 76 | 77 | if (m_dCWndSize >= m_issthresh) 78 | m_bSlowStart = false; 79 | } 80 | else 81 | m_dCWndSize += 1.0/m_dCWndSize; 82 | } 83 | 84 | virtual void DupACKAction() 85 | { 86 | m_bSlowStart = false; 87 | 88 | m_issthresh = getPerfInfo()->pktFlightSize / 2; 89 | if (m_issthresh < 2) 90 | m_issthresh = 2; 91 | 92 | m_dCWndSize = m_issthresh + 3; 93 | } 94 | 95 | protected: 96 | int m_issthresh; 97 | bool m_bSlowStart; 98 | 99 | int m_iDupACKCount; 100 | int m_iLastACK; 101 | }; 102 | 103 | 104 | class CUDPBlast: public CCC 105 | { 106 | public: 107 | CUDPBlast() 108 | { 109 | m_dPktSndPeriod = 1000000; 110 | m_dCWndSize = 83333.0; 111 | } 112 | 113 | public: 114 | void setRate(double mbps) 115 | { 116 | m_dPktSndPeriod = (m_iMSS * 8.0) / mbps; 117 | } 118 | }; 119 | -------------------------------------------------------------------------------- /udt/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/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/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/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/tuner/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 | #include "cc.h" 14 | 15 | using namespace std; 16 | 17 | int main(int argc, char* argv[]) 18 | { 19 | if (argc != 9) { 20 | cout << "usage: recvfile server_ip server_port remote_filename local_filename use_blast(0 or 1) udt_sendbuff udp_sendbuff mss" << 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 | int blast = atoi(argv[5]); 37 | int udt_recvbuff = atoi(argv[6]); 38 | int udp_recvbuff = atoi(argv[7]); 39 | int mss = atoi(argv[8]); 40 | //buffer_size = udt_recvbuff; 41 | 42 | 43 | // UDT Options 44 | if (blast) 45 | UDT::setsockopt(fhandle, 0, UDT_CC, new CCCFactory, sizeof(CCCFactory)); 46 | 47 | UDT::setsockopt(fhandle, 0, UDT_MSS, &mss, sizeof(int)); 48 | UDT::setsockopt(fhandle, 0, UDT_RCVBUF, &udt_recvbuff, sizeof(int)); 49 | UDT::setsockopt(fhandle, 0, UDP_RCVBUF, &udp_recvbuff, sizeof(int)); 50 | UDT::setsockopt(fhandle, 0, UDT_SNDBUF, &udt_recvbuff, sizeof(int)); 51 | UDT::setsockopt(fhandle, 0, UDP_SNDBUF, &udp_recvbuff, sizeof(int)); 52 | 53 | 54 | if (0 != getaddrinfo(argv[1], argv[2], &hints, &peer)) 55 | { 56 | cout << "incorrect server/peer address. " << argv[1] << ":" << argv[2] << endl; 57 | return -1; 58 | } 59 | 60 | // connect to the server, implict bind 61 | if (UDT::ERROR == UDT::connect(fhandle, peer->ai_addr, peer->ai_addrlen)) 62 | { 63 | cout << "connect: " << UDT::getlasterror().getErrorMessage() << endl; 64 | return -1; 65 | } 66 | 67 | freeaddrinfo(peer); 68 | 69 | 70 | // send name information of the requested file 71 | int len = strlen(argv[3]); 72 | 73 | if (UDT::ERROR == UDT::send(fhandle, (char*)&len, sizeof(int), 0)) 74 | { 75 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 76 | return -1; 77 | } 78 | 79 | if (UDT::ERROR == UDT::send(fhandle, argv[3], len, 0)) 80 | { 81 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 82 | return -1; 83 | } 84 | 85 | // get size information 86 | int64_t size; 87 | 88 | if (UDT::ERROR == UDT::recv(fhandle, (char*)&size, sizeof(int64_t), 0)) 89 | { 90 | cout << "send: " << UDT::getlasterror().getErrorMessage() << endl; 91 | return -1; 92 | } 93 | 94 | if (size < 0) 95 | { 96 | cout << "no such file " << argv[3] << " on the server\n"; 97 | return -1; 98 | } 99 | 100 | // receive the file 101 | fstream ofs(argv[4], ios::out | ios::binary | ios::trunc); 102 | int64_t recvsize; 103 | int64_t offset = 0; 104 | 105 | if (UDT::ERROR == (recvsize = UDT::recvfile(fhandle, ofs, offset, size))) 106 | { 107 | cout << "recvfile: " << UDT::getlasterror().getErrorMessage() << endl; 108 | return -1; 109 | } 110 | 111 | UDT::close(fhandle); 112 | 113 | ofs.close(); 114 | 115 | // use this function to release the UDT library 116 | UDT::cleanup(); 117 | 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /udt/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/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/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 |
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.
70 | 71 |
Description
72 |

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 73 | 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.

74 |

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

76 |

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 77 | the timer expires, zero will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.

78 | 79 |
See Also
80 |

select, send, sendfile, recvfile

81 |

 

82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /udt/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 |
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.
67 | 68 |
Description
69 |

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 70 | 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 71 | 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, 72 | but the message will still be discarded after this recvmsg call.

73 |

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

75 |

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 76 | no message available when the timer expires, zero will be returned. UDT_RCVTIMEO has no effect for non-blocking socket.

77 | 78 |
See Also
79 |

select, send

80 |

 

81 | 82 | 83 | 84 | -------------------------------------------------------------------------------- /udt/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 |
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.
EPEERERR7000The peer side has an unrecoverable error and this call has to be cancelled.
75 | 76 |
Description
77 |

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

79 |

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

81 |

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 82 | buffer space available when the timer expires, zero will be returned. UDT_SNDTIMEO has no effect for non-blocking socket.

83 | 84 |
See Also
85 |

select, send, sendfile, recvfile

86 |

 

87 | 88 | 89 | 90 | -------------------------------------------------------------------------------- /udt/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 | -------------------------------------------------------------------------------- /udt/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/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/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/app/udcat_client.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of . 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include "cc.h" 27 | #include "udcat_common.h" 28 | 29 | using std::cerr; 30 | using std::endl; 31 | 32 | int main(int argc, char* argv[]) 33 | { 34 | if (argc != 8) 35 | { 36 | cerr << "usage: appclient server_ip server_port use_blast(0 or 1) udt_sendbuff udp_sendbuff mss" << endl; 37 | return 1; 38 | } 39 | 40 | UDT::startup(); 41 | 42 | struct addrinfo hints, *local, *peer; 43 | 44 | memset(&hints, 0, sizeof(struct addrinfo)); 45 | 46 | hints.ai_flags = AI_PASSIVE; 47 | hints.ai_family = AF_INET; 48 | hints.ai_socktype = SOCK_STREAM; 49 | 50 | if (0 != getaddrinfo(NULL, "9000", &hints, &local)) 51 | { 52 | cerr << "incorrect network address.\n" << endl; 53 | return 1; 54 | } 55 | 56 | 57 | UDTSOCKET client = UDT::socket(local->ai_family, local->ai_socktype, local->ai_protocol); 58 | 59 | int blast = atoi(argv[3]); 60 | int udt_sendbuff = atoi(argv[4]); 61 | int udp_sendbuff = atoi(argv[5]); 62 | int mss = atoi(argv[6]); 63 | int blast_rate = atoi(argv[7]); 64 | 65 | 66 | // UDT Options 67 | if (blast) 68 | UDT::setsockopt(client, 0, UDT_CC, new CCCFactory, sizeof(CCCFactory)); 69 | 70 | UDT::setsockopt(client, 0, UDT_MSS, &mss, sizeof(int)); 71 | UDT::setsockopt(client, 0, UDT_SNDBUF, &udt_sendbuff, sizeof(int)); 72 | UDT::setsockopt(client, 0, UDP_SNDBUF, &udp_sendbuff, sizeof(int)); 73 | 74 | 75 | freeaddrinfo(local); 76 | 77 | if (0 != getaddrinfo(argv[1], argv[2], &hints, &peer)) 78 | { 79 | cerr << "incorrect server/peer address. " << argv[1] << ":" << argv[2] << endl; 80 | return 1; 81 | } 82 | 83 | // connect to the server, implict bind 84 | if (UDT::ERROR == UDT::connect(client, peer->ai_addr, peer->ai_addrlen)) 85 | { 86 | cerr << "connect: " << UDT::getlasterror().getErrorMessage() << endl; 87 | return 1; 88 | } 89 | 90 | pthread_t rcvthread; 91 | pthread_create(&rcvthread, NULL, recvdata, new UDTSOCKET(client)); 92 | pthread_detach(rcvthread); 93 | 94 | freeaddrinfo(peer); 95 | 96 | if (blast) { 97 | CUDPBlast* cchandle = NULL; 98 | int temp; 99 | UDT::getsockopt(client, 0, UDT_CC, &cchandle, &temp); 100 | if (NULL != cchandle) 101 | cchandle->setRate(blast_rate); 102 | } 103 | 104 | size_t buf_size = udt_sendbuff; 105 | int size; 106 | char* data = NULL; 107 | 108 | while ((size = getline(&data, &buf_size, stdin)) > 0) { 109 | int ssize = 0; 110 | int ss; 111 | while (ssize < size) { 112 | if (UDT::ERROR == (ss = UDT::send(client, data + ssize, size - ssize, 0))) { 113 | cerr << "send:" << UDT::getlasterror().getErrorMessage() << endl; 114 | break; 115 | } 116 | 117 | ssize += ss; 118 | } 119 | 120 | if (ssize < size) 121 | break; 122 | } 123 | 124 | UDT::close(client); 125 | 126 | free(data); 127 | 128 | UDT::cleanup(); 129 | 130 | return 0; 131 | } 132 | 133 | -------------------------------------------------------------------------------- /udt/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, const 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/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 | 15 | using namespace std; 16 | 17 | #ifndef WIN32 18 | void* recvdata(void*); 19 | #else 20 | DWORD WINAPI recvdata(LPVOID); 21 | #endif 22 | 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 | // use this function to initialize the UDT library 33 | UDT::startup(); 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 | // use this function to release the UDT library 109 | UDT::cleanup(); 110 | 111 | return 1; 112 | } 113 | 114 | #ifndef WIN32 115 | void* recvdata(void* usocket) 116 | #else 117 | DWORD WINAPI recvdata(LPVOID usocket) 118 | #endif 119 | { 120 | UDTSOCKET recver = *(UDTSOCKET*)usocket; 121 | delete (UDTSOCKET*)usocket; 122 | 123 | char* data; 124 | int size = 100000; 125 | data = new char[size]; 126 | 127 | while (true) 128 | { 129 | int rsize = 0; 130 | int rs; 131 | while (rsize < size) 132 | { 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/app/udcat_server.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2013 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of udr/udt 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include "cc.h" 26 | 27 | #include "udcat_common.h" 28 | 29 | using std::cerr; 30 | using std::endl; 31 | using std::string; 32 | 33 | void* recvdata(void*); 34 | void* senddata(void*); 35 | 36 | int buffer_size; 37 | 38 | int main(int argc, char* argv[]) 39 | { 40 | if (argc != 6) { 41 | cerr << "usage: appserver server_port use_blast(0 or 1) udt_recvbuff " 42 | "udp_recvbuff mss" << endl; 43 | return 1; 44 | } 45 | 46 | UDT::startup(); 47 | 48 | addrinfo hints; 49 | addrinfo* res; 50 | 51 | memset(&hints, 0, sizeof(struct addrinfo)); 52 | 53 | hints.ai_flags = AI_PASSIVE; 54 | hints.ai_family = AF_INET; 55 | hints.ai_socktype = SOCK_STREAM; 56 | 57 | string service("9000"); 58 | if (2 == argc) 59 | service = argv[1]; 60 | 61 | if (0 != getaddrinfo(NULL, service.c_str(), &hints, &res)) { 62 | cerr << "illegal port number or port is busy.\n" << endl; 63 | return 1; 64 | } 65 | 66 | UDTSOCKET serv = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protocol); 67 | 68 | int blast = atoi(argv[2]); 69 | int udt_recvbuff = atoi(argv[3]); 70 | int udp_recvbuff = atoi(argv[4]); 71 | int mss = atoi(argv[5]); 72 | buffer_size = udt_recvbuff; 73 | 74 | // UDT Options 75 | if (blast) 76 | UDT::setsockopt(serv, 0, UDT_CC, new CCCFactory, sizeof(CCCFactory)); 77 | 78 | UDT::setsockopt(serv, 0, UDT_MSS, &mss, sizeof(int)); 79 | UDT::setsockopt(serv, 0, UDT_RCVBUF, &udt_recvbuff, sizeof(int)); 80 | UDT::setsockopt(serv, 0, UDP_RCVBUF, &udp_recvbuff, sizeof(int)); 81 | 82 | 83 | if (UDT::ERROR == UDT::bind(serv, res->ai_addr, res->ai_addrlen)) { 84 | cerr << "bind: " << UDT::getlasterror().getErrorMessage() << endl; 85 | return 1; 86 | } 87 | 88 | freeaddrinfo(res); 89 | 90 | cerr << "server is ready at port: " << service << endl; 91 | 92 | if (UDT::ERROR == UDT::listen(serv, 10)) 93 | { 94 | cerr << "listen: " << UDT::getlasterror().getErrorMessage() << endl; 95 | return 1; 96 | } 97 | 98 | sockaddr_storage clientaddr; 99 | int addrlen = sizeof(clientaddr); 100 | 101 | UDTSOCKET recver; 102 | 103 | while (true) { 104 | if (UDT::INVALID_SOCK == (recver = UDT::accept(serv, 105 | (sockaddr*)&clientaddr, &addrlen))) { 106 | 107 | cerr << "accept: " << UDT::getlasterror().getErrorMessage() << endl; 108 | return 1; 109 | } 110 | 111 | char clienthost[NI_MAXHOST]; 112 | char clientservice[NI_MAXSERV]; 113 | getnameinfo((sockaddr *)&clientaddr, addrlen, clienthost, 114 | sizeof(clienthost), clientservice, sizeof(clientservice), 115 | NI_NUMERICHOST|NI_NUMERICSERV); 116 | 117 | cerr << "new connection: " << clienthost << ":" << clientservice << endl; 118 | 119 | pthread_t rcvthread; 120 | pthread_t sendthread; 121 | pthread_create(&rcvthread, NULL, recvdata, new UDTSOCKET(recver)); 122 | pthread_create(&sendthread, NULL, senddata, new UDTSOCKET(recver)); 123 | pthread_detach(rcvthread); 124 | pthread_detach(sendthread); 125 | } 126 | 127 | UDT::close(serv); 128 | 129 | UDT::cleanup(); 130 | 131 | return 0; 132 | } 133 | 134 | -------------------------------------------------------------------------------- /udt/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/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/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 | -------------------------------------------------------------------------------- /server/daemon.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys, os, time, atexit 4 | from signal import SIGTERM 5 | 6 | class Daemon: 7 | """ 8 | A generic daemon class, based on http://www.jejik.com/articles/2007/02/a_simple_unix_linux_daemon_in_python/ 9 | 10 | Usage: subclass the Daemon class and override the run() method 11 | """ 12 | def __init__(self, pidfile, stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): 13 | self.stdin = stdin 14 | self.stdout = stdout 15 | self.stderr = stderr 16 | self.pidfile = pidfile 17 | 18 | def daemonize(self): 19 | """ 20 | do the UNIX double-fork magic, see Stevens' "Advanced 21 | Programming in the UNIX Environment" for details (ISBN 0201563177) 22 | http://www.erlenstar.demon.co.uk/unix/faq_2.html#SEC16 23 | """ 24 | try: 25 | pid = os.fork() 26 | if pid > 0: 27 | # exit first parent 28 | sys.exit(0) 29 | except OSError, e: 30 | sys.stderr.write("[FAIL] fork #1: %d (%s)\n" % (e.errno, e.strerror)) 31 | sys.exit(1) 32 | 33 | # decouple from parent environment 34 | os.chdir("/") 35 | os.setsid() 36 | os.umask(0) 37 | 38 | # do second fork 39 | try: 40 | pid = os.fork() 41 | if pid > 0: 42 | # exit from second parent 43 | sys.exit(0) 44 | except OSError, e: 45 | sys.stderr.write("[FAIL] fork #2: %d (%s)\n" % (e.errno, e.strerror)) 46 | sys.exit(1) 47 | 48 | # write pidfile 49 | pid = str(os.getpid()) 50 | file(self.pidfile,'w+').write("%s\n" % pid) 51 | 52 | atexit.register(self.delpid) 53 | 54 | # redirect standard file descriptors 55 | sys.stdout.flush() 56 | sys.stderr.flush() 57 | si = file(self.stdin, 'r') 58 | so = file(self.stdout, 'a+') 59 | se = file(self.stderr, 'a+', 0) 60 | os.dup2(si.fileno(), sys.stdin.fileno()) 61 | os.dup2(so.fileno(), sys.stdout.fileno()) 62 | os.dup2(se.fileno(), sys.stderr.fileno()) 63 | 64 | def delpid(self): 65 | os.remove(self.pidfile) 66 | 67 | def start(self): 68 | """ 69 | Start the daemon 70 | """ 71 | # Check for a pidfile to see if the daemon already runs 72 | try: 73 | pf = file(self.pidfile,'r') 74 | pid = int(pf.read().strip()) 75 | pf.close() 76 | except IOError: 77 | pid = None 78 | 79 | if pid: 80 | message = "[FAIL] pidfile %s already exists. Daemon already running?\n" 81 | sys.stderr.write(message % self.pidfile) 82 | sys.exit(1) 83 | 84 | # Start the daemon 85 | self.daemonize() 86 | self.run() 87 | 88 | def stop(self): 89 | """ 90 | Stop the daemon 91 | """ 92 | # Get the pid from the pidfile 93 | try: 94 | pf = file(self.pidfile,'r') 95 | pid = int(pf.read().strip()) 96 | pf.close() 97 | except IOError: 98 | pid = None 99 | 100 | if not pid: 101 | message = "[FAIL] pidfile %s does not exist. Daemon not running?\n" 102 | sys.stderr.write(message % self.pidfile) 103 | return # not an error in a restart 104 | 105 | # Try killing the daemon process 106 | try: 107 | while 1: 108 | os.kill(pid, SIGTERM) 109 | time.sleep(0.1) 110 | except OSError, err: 111 | err = str(err) 112 | if err.find("No such process") > 0: 113 | if os.path.exists(self.pidfile): 114 | os.remove(self.pidfile) 115 | else: 116 | sys.stderr.write("[FAIL]\n%s\n" % str(err)) 117 | sys.exit(1) 118 | 119 | #def restart(self): 120 | # """ 121 | # Restart the daemon 122 | # """ 123 | # self.stop() 124 | # self.start() 125 | 126 | def run(self): 127 | """ 128 | You should override this method when you subclass Daemon. It will be called after the process has been 129 | daemonized by start() or restart(). 130 | """ 131 | -------------------------------------------------------------------------------- /udt/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 | -------------------------------------------------------------------------------- /src/udr_util.cpp: -------------------------------------------------------------------------------- 1 | /***************************************************************************** 2 | Copyright 2012 Laboratory for Advanced Computing at the University of Chicago 3 | 4 | This file is part of UDR. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions 16 | and limitations under the License. 17 | *****************************************************************************/ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | #include 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include "udr_util.h" 36 | 37 | pid_t fork_execvp(const char *program, char* argv[], int * ptc, int * ctp){ 38 | pid_t pid; 39 | 40 | int parent_to_child[2], child_to_parent[2]; 41 | 42 | //for debugging... 43 | // char* arg; 44 | // int idx = 0; 45 | // while((arg = argv[idx]) != NULL){ 46 | // fprintf(stderr, "%s arg[%d]: %s\n", program, idx, arg); 47 | // idx++; 48 | // } 49 | 50 | if(pipe(parent_to_child) != 0 || pipe(child_to_parent) != 0){ 51 | perror("Pipe cannot be created"); 52 | exit(1); 53 | } 54 | 55 | pid = fork(); 56 | 57 | if(pid == 0){ 58 | //child 59 | close(parent_to_child[1]); 60 | dup2(parent_to_child[0], 0); 61 | close(child_to_parent[0]); 62 | dup2(child_to_parent[1], 1); 63 | 64 | execvp(program, argv); 65 | perror(program); 66 | exit(1); 67 | } 68 | else if(pid == -1){ 69 | fprintf(stderr, "Error starting %s\n", program); 70 | exit(1); 71 | } 72 | else{ 73 | //parent 74 | close(parent_to_child[0]); 75 | *ptc = parent_to_child[1]; 76 | close(child_to_parent[1]); 77 | *ctp = child_to_parent[0]; 78 | } 79 | return pid; 80 | } 81 | 82 | void sigchld_handler(int s) 83 | { 84 | while(waitpid(-1, NULL, WNOHANG) > 0); 85 | } 86 | 87 | // get sockaddr, IPv4 or IPv6: 88 | void *get_in_addr(struct sockaddr *sa) 89 | { 90 | if (sa->sa_family == AF_INET) { 91 | return &(((struct sockaddr_in*)sa)->sin_addr); 92 | } 93 | 94 | return &(((struct sockaddr_in6*)sa)->sin6_addr); 95 | } 96 | 97 | int get_server_connection(char * host, char * port, char * udr_cmd, char * line, int line_size){ 98 | //first check to see udr server is running.... 99 | 100 | int sockfd, numbytes; 101 | struct addrinfo hints, *servinfo, *p; 102 | int rv; 103 | char s[INET6_ADDRSTRLEN]; 104 | 105 | memset(&hints, 0, sizeof hints); 106 | hints.ai_family = AF_UNSPEC; 107 | hints.ai_socktype = SOCK_STREAM; 108 | 109 | if((rv = getaddrinfo(host, port, &hints, &servinfo)) != 0){ 110 | fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(rv)); 111 | return 0; 112 | } 113 | 114 | for(p = servinfo; p != NULL; p = p->ai_next){ 115 | if((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) { 116 | //perror("udr client: socket"); 117 | continue; 118 | } 119 | 120 | if(connect(sockfd, p->ai_addr, p->ai_addrlen) == -1){ 121 | close(sockfd); 122 | //perror("udr client: connect"); 123 | continue; 124 | } 125 | 126 | break; 127 | } 128 | 129 | if(p == NULL){ 130 | //fprintf(stderr, "udr error: failed to connect\n"); 131 | return 0; 132 | } 133 | 134 | inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr), s, sizeof s); 135 | 136 | //First send the udr command 137 | //printf("client should be sending: %s\n", udr_cmd); 138 | 139 | if(send(sockfd, udr_cmd, strlen(udr_cmd), 0) == -1){ 140 | perror("udr send"); 141 | exit(1); 142 | } 143 | 144 | freeaddrinfo(servinfo); 145 | 146 | if ((numbytes = recv(sockfd, line, line_size-1, 0)) == -1) { 147 | perror("udr recv"); 148 | exit(1); 149 | } 150 | 151 | line[numbytes] = '\0'; 152 | 153 | close(sockfd); 154 | 155 | return 1; 156 | } 157 | -------------------------------------------------------------------------------- /udt/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/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/tuner/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 | 15 | using namespace std; 16 | 17 | #ifndef WIN32 18 | void* recvdata(void*); 19 | #else 20 | DWORD WINAPI recvdata(LPVOID); 21 | #endif 22 | 23 | int buffer_size; 24 | 25 | int main(int argc, char* argv[]) 26 | { 27 | if (argc != 6) { 28 | cout << "usage: appserver server_port use_blast(0 or 1) udt_recvbuff " 29 | "udp_recvbuff mss" << endl; 30 | return 0; 31 | } 32 | 33 | // use this function to initialize the UDT library 34 | UDT::startup(); 35 | 36 | addrinfo hints; 37 | addrinfo* res; 38 | 39 | memset(&hints, 0, sizeof(struct addrinfo)); 40 | 41 | hints.ai_flags = AI_PASSIVE; 42 | hints.ai_family = AF_INET; 43 | hints.ai_socktype = SOCK_STREAM; 44 | //hints.ai_socktype = SOCK_DGRAM; 45 | 46 | string service("9000"); 47 | if (2 <= argc) 48 | service = argv[1]; 49 | 50 | if (0 != getaddrinfo(NULL, service.c_str(), &hints, &res)) 51 | { 52 | cout << "illegal port number or port is busy.\n" << endl; 53 | return 0; 54 | } 55 | 56 | UDTSOCKET serv = UDT::socket(res->ai_family, res->ai_socktype, res->ai_protocol); 57 | 58 | int blast = atoi(argv[2]); 59 | int udt_recvbuff = atoi(argv[3]); 60 | int udp_recvbuff = atoi(argv[4]); 61 | int mss = atoi(argv[5]); 62 | buffer_size = udt_recvbuff; 63 | 64 | 65 | // UDT Options 66 | if (blast) 67 | UDT::setsockopt(serv, 0, UDT_CC, new CCCFactory, sizeof(CCCFactory)); 68 | 69 | UDT::setsockopt(serv, 0, UDT_MSS, &mss, sizeof(int)); 70 | UDT::setsockopt(serv, 0, UDT_RCVBUF, &udt_recvbuff, sizeof(int)); 71 | UDT::setsockopt(serv, 0, UDP_RCVBUF, &udp_recvbuff, sizeof(int)); 72 | 73 | if (UDT::ERROR == UDT::bind(serv, res->ai_addr, res->ai_addrlen)) 74 | { 75 | cout << "bind: " << UDT::getlasterror().getErrorMessage() << endl; 76 | return 0; 77 | } 78 | 79 | freeaddrinfo(res); 80 | 81 | cout << "server is ready at port: " << service << endl; 82 | 83 | if (UDT::ERROR == UDT::listen(serv, 10)) 84 | { 85 | cout << "listen: " << UDT::getlasterror().getErrorMessage() << endl; 86 | return 0; 87 | } 88 | 89 | sockaddr_storage clientaddr; 90 | int addrlen = sizeof(clientaddr); 91 | 92 | UDTSOCKET recver; 93 | 94 | while (true) 95 | { 96 | if (UDT::INVALID_SOCK == (recver = UDT::accept(serv, (sockaddr*)&clientaddr, &addrlen))) 97 | { 98 | cout << "accept: " << UDT::getlasterror().getErrorMessage() << endl; 99 | return 0; 100 | } 101 | 102 | char clienthost[NI_MAXHOST]; 103 | char clientservice[NI_MAXSERV]; 104 | getnameinfo((sockaddr *)&clientaddr, addrlen, clienthost, sizeof(clienthost), clientservice, sizeof(clientservice), NI_NUMERICHOST|NI_NUMERICSERV); 105 | cout << "new connection: " << clienthost << ":" << clientservice << endl; 106 | 107 | #ifndef WIN32 108 | pthread_t rcvthread; 109 | pthread_create(&rcvthread, NULL, recvdata, new UDTSOCKET(recver)); 110 | pthread_detach(rcvthread); 111 | #else 112 | CreateThread(NULL, 0, recvdata, new UDTSOCKET(recver), 0, NULL); 113 | #endif 114 | } 115 | 116 | UDT::close(serv); 117 | 118 | // use this function to release the UDT library 119 | UDT::cleanup(); 120 | 121 | return 1; 122 | } 123 | 124 | #ifndef WIN32 125 | void* recvdata(void* usocket) 126 | #else 127 | DWORD WINAPI recvdata(LPVOID usocket) 128 | #endif 129 | { 130 | UDTSOCKET recver = *(UDTSOCKET*)usocket; 131 | delete (UDTSOCKET*)usocket; 132 | 133 | char* data; 134 | int size = buffer_size; 135 | data = new char[size]; 136 | 137 | while (true) 138 | { 139 | int rsize = 0; 140 | int rs; 141 | while (rsize < size) 142 | { 143 | if (UDT::ERROR == (rs = UDT::recv(recver, data + rsize, size - rsize, 0))) 144 | { 145 | cout << "recv:" << UDT::getlasterror().getErrorMessage() << endl; 146 | break; 147 | } 148 | 149 | rsize += rs; 150 | } 151 | 152 | if (rsize < size) 153 | break; 154 | } 155 | 156 | delete [] data; 157 | 158 | UDT::close(recver); 159 | 160 | #ifndef WIN32 161 | return NULL; 162 | #else 163 | return 0; 164 | #endif 165 | } 166 | -------------------------------------------------------------------------------- /udt/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/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/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/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 | --------------------------------------------------------------------------------