1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
'\" t
.TH QSocketNotifier 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QSocketNotifier \- Support for socket callbacks
.SH SYNOPSIS
\fC#include <ntqsocketnotifier.h>\fR
.PP
Inherits QObject.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "enum \fBType\fR { Read, Write, Exception }"
.br
.ti -1c
.BI "\fBQSocketNotifier\fR ( int socket, Type type, QObject * parent = 0, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QSocketNotifier\fR ()"
.br
.ti -1c
.BI "int \fBsocket\fR () const"
.br
.ti -1c
.BI "Type \fBtype\fR () const"
.br
.ti -1c
.BI "bool \fBisEnabled\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetEnabled\fR ( bool enable )"
.br
.in -1c
.SS "Signals"
.in +1c
.ti -1c
.BI "void \fBactivated\fR ( int socket )"
.br
.in -1c
.SH DESCRIPTION
The QSocketNotifier class provides support for socket callbacks.
.PP
This class makes it possible to write asynchronous socket-based code in Qt. Using synchronous socket operations blocks the program, which is clearly not acceptable for an event-driven GUI program.
.PP
Once you have opened a non-blocking socket (whether for TCP, UDP, a UNIX-domain socket, or any other protocol family your operating system supports), you can create a socket notifier to monitor the socket. Then you connect the activated() signal to the slot you want to be called when a socket event occurs.
.PP
Note for Windows users: the socket passed to QSocketNotifier will become non-blocking, even if it was created as a blocking socket.
.PP
There are three types of socket notifiers (read, write and exception); you must specify one of these in the constructor.
.PP
The type specifies when the activated() signal is to be emitted: <ol type=1>
.IP 1
QSocketNotifier::Read - There is data to be read (socket read event).
.IP 2
QSocketNotifier::Write - Data can be written (socket write event).
.IP 3
QSocketNofifier::Exception - An exception has occurred (socket exception event). We recommend against using this.
.PP
For example, if you need to monitor both reads and writes for the same socket you must create two socket notifiers.
.PP
For read notifiers it makes little sense to connect the activated() signal to more than one slot because the data can be read from the socket only once.
.PP
Also observe that if you do not read all the available data when the read notifier fires, it fires again and again.
.PP
For write notifiers, immediately disable the notifier after the activated() signal has been received and you have sent the data to be written on the socket. When you have more data to be written, enable it again to get a new activated() signal. The exception is if the socket data writing operation (send() or equivalent) fails with a "would block" error, which means that some buffer is full and you must wait before sending more data. In that case you do not need to disable and re-enable the write notifier; it will fire again as soon as the system allows more data to be sent.
.PP
The behavior of a write notifier that is left in enabled state after having emitting the first activated() signal (and no "would block" error has occurred) is undefined. Depending on the operating system, it may fire on every pass of the event loop or not at all.
.PP
If you need a time-out for your sockets you can use either timer events or the QTimer class.
.PP
Socket action is detected in the main event loop of Qt. The X11 version of TQt has a single UNIX select() call that incorporates all socket notifiers and the X socket.
.PP
Note that on XFree86 for OS/2, select() works only in the thread in which main() is running; you should therefore use that thread for GUI operations.
.PP
See also QSocket, QServerSocket, QSocketDevice, QFile::handle(), and Input/Output and Networking.
.SS "Member Type Documentation"
.SH "QSocketNotifier::Type"
.TP
\fCQSocketNotifier::Read\fR
.TP
\fCQSocketNotifier::Write\fR
.TP
\fCQSocketNotifier::Exception\fR
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QSocketNotifier::QSocketNotifier ( int socket, Type type, QObject * parent = 0, const char * name = 0 )"
Constructs a socket notifier called \fIname\fR, with the parent, \fIparent\fR. It watches \fIsocket\fR for \fItype\fR events, and enables it.
.PP
It is generally advisable to explicitly enable or disable the socket notifier, especially for write notifiers.
.PP
See also setEnabled() and isEnabled().
.SH "QSocketNotifier::~QSocketNotifier ()"
Destroys the socket notifier.
.SH "void QSocketNotifier::activated ( int socket )\fC [signal]\fR"
This signal is emitted under certain conditions specified by the notifier type(): <ol type=1>
.TP
QSocketNotifier::Read - There is data to be read (socket read event).
.TP
QSocketNotifier::Write - Data can be written (socket write event).
.TP
QSocketNofifier::Exception - An exception has occurred (socket exception event).
.PP
The \fIsocket\fR argument is the socket identifier.
.PP
See also type() and socket().
.SH "bool QSocketNotifier::isEnabled () const"
Returns TRUE if the notifier is enabled; otherwise returns FALSE.
.PP
See also setEnabled().
.SH "void QSocketNotifier::setEnabled ( bool enable )\fC [virtual]\fR"
Enables the notifier if \fIenable\fR is TRUE or disables it if \fIenable\fR is FALSE.
.PP
The notifier is enabled by default.
.PP
If the notifier is enabled, it emits the activated() signal whenever a socket event corresponding to its type occurs. If it is disabled, it ignores socket events (the same effect as not creating the socket notifier).
.PP
Write notifiers should normally be disabled immediately after the activated() signal has been emitted; see discussion of write notifiers in the class description above.
.PP
See also isEnabled() and activated().
.SH "int QSocketNotifier::socket () const"
Returns the socket identifier specified to the constructor.
.PP
See also type().
.SH "Type QSocketNotifier::type () const"
Returns the socket event type specified to the constructor: QSocketNotifier::Read, QSocketNotifier::Write, or QSocketNotifier::Exception.
.PP
See also socket().
.SH "SEE ALSO"
.BR http://doc.trolltech.com/ntqsocketnotifier.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If 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.
.P
The definitive TQt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using TQt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (tqsocketnotifier.3qt) and the Qt
version (3.3.8).
|