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

📄 qsocketdevice.3qt

📁 Linux下的基于X11的图形开发环境。
💻 3QT
字号:
'\" t.TH QSocketDevice 3qt "9 December 2002" "Trolltech AS" \" -*- nroff -*-.\" Copyright 1992-2001 Trolltech AS.  All rights reserved.  See the.\" license file included in the distribution for a complete license.\" statement..\".ad l.nh.SH NAMEQSocketDevice \- Platform-independent low-level socket API.SH SYNOPSIS\fC#include <qsocketdevice.h>\fR.PPInherits QIODevice..PP.SS "Public Members".in +1c.ti -1c.BI "enum \fBType\fR { Stream, Datagram }".br.ti -1c.BI "\fBQSocketDevice\fR ( Type type = Stream )".br.ti -1c.BI "\fBQSocketDevice\fR ( int socket, Type type )".br.ti -1c.BI "virtual \fB~QSocketDevice\fR ()".br.ti -1c.BI "bool \fBisValid\fR () const".br.ti -1c.BI "Type \fBtype\fR () const".br.ti -1c.BI "int \fBsocket\fR () const".br.ti -1c.BI "virtual void \fBsetSocket\fR ( int socket, Type type )".br.ti -1c.BI "bool \fBblocking\fR () const".br.ti -1c.BI "virtual void \fBsetBlocking\fR ( bool enable )".br.ti -1c.BI "bool \fBaddressReusable\fR () const".br.ti -1c.BI "virtual void \fBsetAddressReusable\fR ( bool enable )".br.ti -1c.BI "int \fBreceiveBufferSize\fR () const".br.ti -1c.BI "virtual void \fBsetReceiveBufferSize\fR ( uint size )".br.ti -1c.BI "int \fBsendBufferSize\fR () const".br.ti -1c.BI "virtual void \fBsetSendBufferSize\fR ( uint size )".br.ti -1c.BI "virtual bool \fBconnect\fR ( const QHostAddress & addr, Q_UINT16 port )".br.ti -1c.BI "virtual bool \fBbind\fR ( const QHostAddress & address, Q_UINT16 port )".br.ti -1c.BI "virtual bool \fBlisten\fR ( int backlog )".br.ti -1c.BI "virtual int \fBaccept\fR ()".br.ti -1c.BI "Q_LONG \fBbytesAvailable\fR () const".br.ti -1c.BI "Q_LONG \fBwaitForMore\fR ( int msecs, bool * timeout = 0 ) const".br.ti -1c.BI "virtual Q_LONG \fBreadBlock\fR ( char * data, Q_ULONG maxlen )".br.ti -1c.BI "virtual Q_LONG \fBwriteBlock\fR ( const char * data, Q_ULONG len )".br.ti -1c.BI "virtual Q_LONG \fBwriteBlock\fR ( const char * data, Q_ULONG len, const QHostAddress & host, Q_UINT16 port )".br.ti -1c.BI "Q_UINT16 \fBport\fR () const".br.ti -1c.BI "Q_UINT16 \fBpeerPort\fR () const".br.ti -1c.BI "QHostAddress \fBaddress\fR () const".br.ti -1c.BI "QHostAddress \fBpeerAddress\fR () const".br.ti -1c.BI "enum \fBError\fR { NoError, AlreadyBound, Inaccessible, NoResources, InternalError, Bug = InternalError, Impossible, NoFiles, ConnectionRefused, NetworkFailure, UnknownError }".br.ti -1c.BI "Error \fBerror\fR () const".br.in -1c.SS "Protected Members".in +1c.ti -1c.BI "void \fBsetError\fR ( Error err )".br.in -1c.SH DESCRIPTIONThe QSocketDevice class provides a platform-independent low-level socket API..PPThis class provides a low level API for working with sockets. Users of this class are assumed to have networking experience. For most users the QSocket class provides a much easier and high level alternative, but certain thing (like UDP) can't be done with QSocket and if you need a platform-independent API for those, QSocketDevice is the right choice..PPThe essential purpose of the class is to provide a QIODevice that works on sockets, wrapped in a platform-independent API..PPSee also QSocket, QSocketNotifier, QHostAddress, and Input/Output and Networking..SS "Member Type Documentation".SH "QSocketDevice::Error"This enum type describes the error states of QSocketDevice..TP\fCQSocketDevice::NoError\fR - No error has occurred..TP\fCQSocketDevice::AlreadyBound\fR - The device is already bound, according to bind()..TP\fCQSocketDevice::Inaccessible\fR - The operating system or firewall prohibited the action..TP\fCQSocketDevice::NoResources\fR - The operating system ran out of a resource..TP\fCQSocketDevice::InternalError\fR - An internal error occurred in QSocketDevice..TP\fCQSocketDevice::Impossible\fR - An attempt was made to do something which makes no sense. For example:.IP.nf.br    ::close( sd->socket() );.br    sd->writeBlock( someData, 42 );.br.fiThe libc ::close() closes the socket, but QSocketDevice is not aware of this. So when you call writeBlock(), the impossible happens..TP\fCQSocketDevice::NoFiles\fR - The operating system will not let QSocketDevice open another file..TP\fCQSocketDevice::ConnectionRefused\fR - A connection attempt was rejected by the peer..TP\fCQSocketDevice::NetworkFailure\fR - There is a network failure..TP\fCQSocketDevice::UnknownError\fR - The operating system did something unexpected..SH "QSocketDevice::Type"This enum type describes the type of the socket:.TP\fCQSocketDevice::Stream\fR - a stream socket (TCP, usually).TP\fCQSocketDevice::Datagram\fR - a datagram socket (UDP, usually).SH MEMBER FUNCTION DOCUMENTATION.SH "QSocketDevice::QSocketDevice ( Type type = Stream )"Creates a QSocketDevice object for a stream or datagram socket..PPThe \fItype\fR argument must be either QSocketDevice::Stream for a reliable, connection-oriented TCP socket, or QSocketDevice::Datagram for an unreliable UDP socket..PPSee also blocking()..SH "QSocketDevice::QSocketDevice ( int socket, Type type )"Creates a QSocketDevice object for the existing socket \fIsocket\fR..PPThe \fItype\fR argument must match the actual socket type; use QSocketDevice::Stream for a reliable, connection-oriented TCP socket, or QSocketDevice::Datagram for an unreliable, connectionless UDP socket..SH "QSocketDevice::~QSocketDevice ()\fC [virtual]\fR"Destroys the socket device and closes the socket if it is open..SH "int QSocketDevice::accept ()\fC [virtual]\fR"Extracts the first connection from the queue of pending connections for this socket and returns a new socket identifier. Returns -1 if the operation failed..PPSee also bind() and listen()..SH "QHostAddress QSocketDevice::address () const"Returns the address of this socket device. This may be 0.0.0.0 for a while, but is set to something sensible as soon as a sensible value is available..SH "bool QSocketDevice::addressReusable () const"Returns TRUE if the address of this socket can be used by other sockets at the same time, and FALSE if this socket claims exclusive ownership..PPSee also setAddressReusable()..SH "bool QSocketDevice::bind ( const QHostAddress & address, Q_UINT16 port )\fC [virtual]\fR"Assigns a name to an unnamed socket. The name is the host address \fIaddress\fR and the port number \fIport\fR. If the operation succeeds, bind() returns TRUE; otherwise it returns FALSE without changing what port() and address() return..PPbind() is used by servers for setting up incoming connections. Call bind() before listen()..SH "bool QSocketDevice::blocking () const"Returns TRUE if the socket is valid and in blocking mode; otherwise returns FALSE..PPNote that this function does not set error()..PP\fBWarning:\fR On Windows, this function always returns TRUE since the ioctlsocket() function is broken..PPSee also setBlocking() and isValid()..SH "Q_LONG QSocketDevice::bytesAvailable () const"Returns the number of bytes available for reading, or -1 if an error occurred..PP\fBWarning:\fR On Microsoft Windows, we use the ioctlsocket() function to determine the number of bytes queued on the socket. According to Microsoft (KB Q125486), ioctlsocket() sometimes returns an incorrect number. The only safe way to determine the amount of data on the socket is to read it using readBlock(). QSocket has workarounds to deal with this problem..SH "bool QSocketDevice::connect ( const QHostAddress & addr, Q_UINT16 port )\fC [virtual]\fR"Connects to the IP address and port specified by \fIaddr\fR and \fIport\fR. Returns TRUE if it establishes a connection; otherwise returns FALSE. If it returns FALSE, error() explains why..PPNote that error() commonly returns NoError for non-blocking sockets; this just means that you can call connect() again in a little while and it'll probably succeed..SH "Error QSocketDevice::error () const"Returns the first error seen..SH "bool QSocketDevice::isValid () const"Returns TRUE if this is a valid socket; otherwise returns FALSE..PPSee also socket()..SH "bool QSocketDevice::listen ( int backlog )\fC [virtual]\fR"Specifies how many pending connections a server socket can have. Returns TRUE if the operation was successful; otherwise returns FALSE..PPThe listen() call only applies to sockets where type() is Stream, i.e. not to Datagram sockets. listen() must not be called before bind() or after accept(). It is common to use a \fIbacklog\fR value of 50 on most Unix systems..PPSee also bind() and accept()..SH "QHostAddress QSocketDevice::peerAddress () const"Returns the address of the port this socket device is connected to. This may be 0.0.0.0 for a while, but is set to something sensible as soon as a sensible value is available..PPNote that for Datagram sockets, this is the source port of the last packet received..SH "Q_UINT16 QSocketDevice::peerPort () const"Returns the port number of the port this socket device is connected to. This may be 0 for a while, but is set to something sensible as soon as a sensible value is available..PPNote that for Datagram sockets, this is the source port of the last packet received, and that it is in native byte order..SH "Q_UINT16 QSocketDevice::port () const"Returns the port number of this socket device. This may be 0 for a while, but is set to something sensible as soon as a sensible value is available..PPNote that Qt always uses native byte order, i.e. 67 is 67 in Qt; there is no need to call htons()..SH "Q_LONG QSocketDevice::readBlock ( char * data, Q_ULONG maxlen )\fC [virtual]\fR"Reads \fImaxlen\fR bytes from the socket into \fIdata\fR and returns the number of bytes read. Returns -1 if an error occurred..PPReimplemented from QIODevice..SH "int QSocketDevice::receiveBufferSize () const"Returns the size of the operating system receive buffer..PPSee also setReceiveBufferSize()..SH "int QSocketDevice::sendBufferSize () const"Returns the size of the operating system send buffer..PPSee also setSendBufferSize()..SH "void QSocketDevice::setAddressReusable ( bool enable )\fC [virtual]\fR"Sets the address of this socket to be usable by other sockets too if \fIenable\fR is TRUE, and to be used exclusively by this socket if \fIenable\fR is FALSE..PPWhen a socket is reusable, other sockets can use the same port number (and IP address), which is generally useful. Of course other sockets cannot use the same (address,port,peer-address,peer-port) 4-tuple as this socket, so there is no risk of confusing the two TCP connections..PPSee also addressReusable()..SH "void QSocketDevice::setBlocking ( bool enable )\fC [virtual]\fR"Makes the socket blocking if \fIenable\fR is TRUE or nonblocking if \fIenable\fR is FALSE..PPSockets are blocking by default, but we recommend using nonblocking socket operations, especially for GUI programs that need to be responsive..PP\fBWarning:\fR On Windows, this function should be used with care since whenever you use a QSocketNotifier on Windows, the socket is immediately made nonblocking..PPSee also blocking() and isValid()..SH "void QSocketDevice::setError ( Error err )\fC [protected]\fR"Allows subclasses to set the error state to \fIerr\fR..SH "void QSocketDevice::setReceiveBufferSize ( uint size )\fC [virtual]\fR"Sets the size of the operating system receive buffer to \fIsize\fR..PPThe operating system receive buffer size effectively limits two things: how much data can be in transit at any one moment, and how much data can be received in one iteration of the main event loop..PPThe default is operating system-dependent. A socket that receives large amounts of data is probably best with a buffer size of 49152..SH "void QSocketDevice::setSendBufferSize ( uint size )\fC [virtual]\fR"Sets the size of the operating system send buffer to \fIsize\fR..PPThe operating system send buffer size effectively limits how much data can be in transit at any one moment..PPThe default is operating system-dependent. A socket that sends large amounts of data is probably best with a buffer size of 49152..SH "void QSocketDevice::setSocket ( int socket, Type type )\fC [virtual]\fR"Sets the socket device to operate on the existing socket \fIsocket\fR..PPThe \fItype\fR argument must match the actual socket type; use QSocketDevice::Stream for a reliable, connection-oriented TCP socket, or QSocketDevice::Datagram for an unreliable, connectionless UDP socket..PPAny existing socket is closed..PPSee also isValid() and close()..SH "int QSocketDevice::socket () const"Returns the socket number, or -1 if it is an invalid socket..PPSee also isValid() and type()..SH "Type QSocketDevice::type () const"Returns the socket type which is either QSocketDevice::Stream or QSocketDevice::Datagram..PPSee also socket()..SH "Q_LONG QSocketDevice::waitForMore ( int msecs, bool * timeout = 0 ) const"Wait up to \fImsecs\fR milliseconds for more data to be available. If \fImsecs\fR is -1 the call will block indefinitely..PPReturns the number of bytes available for reading, or -1 if an error occurred..PPIf \fItimeout\fR is non-null and no error occurred (i.e. it does not return -1): this function sets \fI*timeout\fR to TRUE, if the reason for returning was that the timeout was reached; otherwise it sets \fI*timeout\fR to FALSE. This is useful to find out if the peer closed the connection..PP\fBWarning:\fR This is a blocking call and should be avoided in event driven applications..PPSee also bytesAvailable()..SH "Q_LONG QSocketDevice::writeBlock ( const char * data, Q_ULONG len )\fC [virtual]\fR"Writes \fIlen\fR bytes to the socket from \fIdata\fR and returns the number of bytes written. Returns -1 if an error occurred..PPThis is used for QSocketDevice::Stream sockets..PPReimplemented from QIODevice..SH "Q_LONG QSocketDevice::writeBlock ( const char * data, Q_ULONG len, const QHostAddress & host, Q_UINT16 port )\fC [virtual]\fR"This is an overloaded member function, provided for convenience. It behaves essentially like the above function..PPWrites \fIlen\fR bytes to the socket from \fIdata\fR and returns the number of bytes written. Returns -1 if an error occurred..PPThis is used for QSocketDevice::Datagram sockets. You mustspecify the \fIhost\fR and \fIport\fR of the destination of the data..SH "SEE ALSO".BR http://doc.trolltech.com/qsocketdevice.html.BR http://www.trolltech.com/faq/tech.html.SH COPYRIGHTCopyright 1992-2001 Trolltech AS, http://www.trolltech.com.  See thelicense file included in the distribution for a complete licensestatement..SH AUTHORGenerated automatically from the source code..SH BUGSIf you find a bug in Qt, please report it as described in.BR http://doc.trolltech.com/bughowto.html .Good bug reports help us to help you. Thank you..PThe definitive Qt documentation is provided in HTML format; it islocated at $QTDIR/doc/html and can be read using Qt Assistant or witha web browser. This man page is provided as a convenience for thoseusers who prefer man pages, although this format is not officiallysupported by Trolltech. .PIf you find errors in this manual page, please report them to.BR qt-bugs@trolltech.com .Please include the name of the manual page (qsocketdevice.3qt) and the Qtversion (3.1.1).

⌨️ 快捷键说明

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