?? documentation
字號:
RTSOCK Example CodeWritten by Robert KavalerCopyright (C) 1998-2002, Innomedia, Inc.All rights reserved.Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions aremet: Redistributions of source code must retain the above copyrightnotice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the abovecopyright notice, this list of conditions and the followingdisclaimer in the documentation and/or other materialsprovided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERSAND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIEDWARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR APARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALLTHE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FORANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITEDTO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAYOUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OFTHE POSSIBILITY OF SUCH DAMAGE.The application implemented by this example code is a unidirectional UDPpacket stream that transmits at a constant number of packets per second (2000 in this case). The receive side merely counts packets and printsa message (with time) each 10000 packets. Code is provided for both rt and user space implementations so that one can compare the two implementations.The application is split into two files: rtsock-test.c is an rtlinux/kernelmodule that uses the rtsock interface; and rtsocku is the user space application code and user interface. The rtsocku application starts a single end of a UDP stream for either receive or transmit. Both the receive and transmit functions can be executed either in user space or real timespace, providing a matrix of 4 modes: ru receive in user space rr receive in rt space tu transmit in user space tr transmit in rt spaceThe transmit timing for user space packets is a 0th order PLL referenced togettimeofday. The transmit timing for realtime space packets is thestandard rtlinux task timer. The receive packets are merely counted, butin the real-time case they are counted in the real-time task and then printedto an rtf0 (which is in turn printed by the application). Timing for the user space receive is referenced to gettimeofday, while for thereal-time receive is synchronous to the rtlinux task timer. Thus, jitterof the real-time versus user space implementations can be measured easily.This test/example code allows many user-processes to share a single rtsock by allocating a unique index in the rtsock-test module and passing that index back to the application. The index is a handle to the rt side "MySock" structure. This code demonstrates the new RTSOCK_IOCINTERFACE ioctl call.Installation1. Modify the first line of the Makefile to point to your local copy of thertlinux source code2. Run "make"3. Load the rtlinux modules and then insmod the ../rtsock.o and ./rtsock-test-mod.o modules. One can run "make rtlconfigs configs" asa short-cut.Running the codeTesting UDP networking code can be very complex because it can require botha server and a client and some protocol for exchanging port numbers. Forthe application provided here, it is expected that the user will do these things manually.There are four cases that can be tested. In each case there are twoshells required (one tx, one rx). The shells can be started on eitherthe same machine or on different machines, let's call them IP1 and IP2. IP1 and IP2 are either host names, IP addresses, or 0.0.0.0 (i.e. INADDR_ANY)if left empty. Starting both the rx and tx on the same machine basically means using localhost as the IP address.The receive side should always be started first:rtsocku ru -or- rtsocku rrthis will print the local port number 0.0.0.0:<port>. Now on shell 2 enter:rtsocku tu IP1:<port> -or- rtsocku tr IP1:<port>You should see a message printed every 5 seconds on shell 1.To end the session, kill thereceive side (shell 1) and the transmit side should print a send failed message and stop (this is because the transmit side will receive an ICMP message telling the transmitter that the receiver port is no longer available.)KNOWN BUGS: 1. Currently if either the rr or tr commands are exited by control c,the RtSockets are not destroyed and will never be freed. In order to free them, you must unload the rtsock-test-mod module. In real applications control c should be trapped and all the RtSocket freed automatically.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -