⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pthread_io.3

📁 用c++包装好的线程库,直接拿来使用,提高效率.
💻 3
字号:
.\" Copyright (c) 1999-2000 Orn E. Hansen <oe.hansen@gamma.telenordia.se>.\".\" Permission is granted to make and distribute verbatim copies of this.\" manual provided the copyright notice and this permission notice are.\" preserved on all copies..\".\" Permission is granted to copy and distribute modified versions of this.\" manual under the conditions for verbatim copying, provided that the.\" entire resulting derived work is distributed under the terms of a.\" permission notice identical to this one.\"                                                                            .TH THREADS 3 "10 Feb 2000" "Threads 2.0" "Threads C++ Library".SH NAMEcond \- A class, for process synchronisation..SH SYNOPSIS.B        #include <thread_io.h>.sp 2.B        ....sp 0.B        class myio : public pthread_io {.sp 0.B          protected:.sp 0.B           void got(const char *,int) { /* input method */ };.sp 1.B          public:.sp 0.B           myio() : pthread_io( ... ) { };.sp 0.B           ~myio() { close(fd()); };.sp 0.B        };.sp 0.B        ....SH DESCRIPTIONThe.I pthread_ioclass is a part of the threads C++ library that focuses onsimplifying program threading.By expanding the basic thread class, a threaded IO class isprovieded that gives the programmer asynchronous functionalitythrough input methods in the class.  This simplifies datainput and output from sockets, as well as serial lines.The class is an abstract class, meaning that it needs to bea superclass to another.  Reason for this, is that the methodwhere input from is received needs to be filled in by theprogrammer..LPThere are three ways in which to create a class of thistype.  Constructors are provided to manage a normal filedescriptor, that can be associated with a serial line, ora server socket, or a client socket.The constructors are as follows..TP 10.B pthread_io()It may be useful for a construct of this class, to manageonly outside file descriptors.  Descriptors that may beroaming, opened for a time and closed for a time, withoutbeing permanently managed.  In such an environment, thisconstructor is useful.  No file descriptor is opened ormanaged, nor can there be any server socket management..TP 10.B pthread_io(int)This constructor will manage input from the given filedescriptor.  The descriptor is not thought to be aserver socket, and therefore no client connections areaccepted to it.Typical use for such a construction would be to managea serial input, such as with a modem..TP 10.B pthread_io(const char *,int)This constructor will manage input from a client socket.The constructor is passed the name of the machine toconnect with, and the port on which the connection shouldbe made.On successfull connection, the input is managed..TP 10.B pthread_io(int,int)A server socket is created, with a given port number (thefirst parameter) and enabled for listening.  The lastparameter is the backlog parameter that will be passedto the.B listenfunction.The server socket will be manager and watched for incomingconnections, which will be reported to the.B void open(int)method..LPThe class provides numerous methods to control output to theassociated file descriptors, as well as asynchronous meansof knowing when a client has opened and closed their linkto a server socket.  Some of these methods are listed herewith explanations to their functionality..TP 10.B void got(const char *,int)This method is protected inside the class hierarchy, andcan't be accessed from the outside.  It provides thelink where all data input, coming from the associatedfile descriptors are sent.  The parameters associatedwith method, provide the buffer where the data is storedand the number of bytes in the buffer..TP 10.B void open(int)In the case of a server socket, that is being maintained. Thismethod will be called whenever a client connects to theserver socket.  The method will be passed the file descriptornumber that was being opened..TP 10.B void close(int)When a client closes a connection to a server socket, thefile descriptor being closed will be passed to this method.The programmer should make sure to close the file descriptorif the original method is overwritten, or to call theoriginal method to take care of that task..TP 10.B int put(int,char).TP 10.B int put(char)These two methods, provide means to send a character to anassociated file descriptor.  The programmer can either passthe file descriptor the method, or only pass the characterto write.  In the first case, the file descriptor will bechecked to see if it is a descriptor being maintained bythe class, either as a main file descriptor or one associatedwith a client connected to it's server socket.  If thefile descriptor is not passed to the method, then thecurrent client being served is thought to be the descriptorbeing referred to, or the main descriptor associated withthe class in case it is not maintaining a listening socket.In either case, data will only be put to a file descriptor thatis known to the class.The method returns the number of bytes that were writtento the file descriptor, or -1 if an error occured..TP 10.B int put(int,const char *, int).TP 10.B int put(const char *, int)These methods have the same functionality as the methodsbefore them.  They only differ in the parameter that isto be written to the file descriptor in question.  In thiscase, a whole string will be written, of a given lengthwhich is represented by the last parameter..TP 10.B int put(int,const string&).TP 10.B int put(const string&)Yet another version, of what can be written onto theassociated file descriptor.  This is a wrapper method,that allows strings to be written, instead of passingcharacter pointers.The method is identical to the above, except in thisinstance the length of the string is stored inside thestring class, and needs not be passed to the method..TP 10.B bool failure(int)If an error occurs on a client file descriptor, this methodwill receive the file descriptor where the error occurred.  Themethod should return a true value, if the file descriptoris to be closed as a result of the error, or else a truevalue to have it remain open.The standard method, returns a true value..TP 10.B void register_fd(asynchronous_input *)This method, registers a receiver for input data.  The class.B asynchronous_inputprovides the methods necessary to accept input.  It also hada file descriptor associated with it, and all classes thatare to receive input asynchronously must inherit it.It is possible for the method to throw an exception of type.B pthread_io::exceptionTypeswhich will occur, if one tries to register a file descriptorthat is already registered.  In which case a.B pthread_io::NeedUnregisterwill be issued..TP 10.B void unregister_fd(asynchronous_input *)A method that is the opposite to the.B register_fdmethod.  It will locate the registered class and filedescriptor in its internal tables, and remove them.  Nodata will be accepted from the file descriptor past thatpoint.No exceptions are generated by this method, if thereferred class doesn't exist in the tables, nothing isdone..LPSuggestions and questions about the threads library should bedirected to:.IPkdb-list@brevet.nu.LPOr, to the author specified below.  The threads home page is located at:.IPhttp://user.tninet.se/~dpn659b/threads.html.LP.SH AUTHORVersion 2.0Copyright (C) 1999-2000 Orn E. Hansen <oe.hansen@gamma.telenordia.se>..LPThanks to those who reported their suggestions on how toimprove the threads library.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -