• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
kextsock.h
1/*
2 * This file is part of the KDE libraries
3 * Copyright (C) 2000-2004 Thiago Macieira <thiago.macieira@kdemail.net>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20#ifndef KEXTSOCK_H
21#define KEXTSOCK_H
22
23#include "tdelibs_export.h"
24
25#ifdef Q_OS_UNIX
26
27#include <sys/time.h>
28
29#include <tqstring.h>
30#include <tqptrlist.h>
31#include <tqiodevice.h>
32
33#include "kbufferedio.h"
34#include "ksockaddr.h"
35
36/* External reference to netdb.h */
37struct addrinfo;
38struct kde_addrinfo;
39class KAddressInfo; /* our abstraction of it */
40class TQSocketNotifier;
41
42/*
43 * This is extending TQIODevice's error codes
44 *
45 * According to tqiodevice.h, the last error is IO_UnspecifiedError
46 * These errors will never occur in functions declared in TQIODevice
47 * (except open, but you shouldn't call open)
48 */
49#define IO_ListenError (IO_UnspecifiedError+1)
50#define IO_AcceptError (IO_UnspecifiedError+2)
51#define IO_LookupError (IO_UnspecifiedError+3)
52
53class KExtendedSocketPrivate;
91class TDECORE_EXPORT KExtendedSocket: public TDEBufferedIO // public TQObject, public TQIODevice
92{
93 TQ_OBJECT
94
95
96public:
100 enum Flags
101 {
102 /* socket address families */
103 /*
104 * NOTE: if you change this, you have to change function valid_socket() as well
105 * These values are hard coded!
106 */
107 anySocket = 0x00,
108 knownSocket = 0x01,
109 unixSocket = knownSocket | 0x02,
110 inetSocket = knownSocket | 0x04,
111 ipv4Socket = inetSocket | 0x100,
112 ipv6Socket = inetSocket | 0x200,
113
114 passiveSocket = 0x1000, /* passive socket (i.e., one that accepts connections) */
115 canonName = 0x2000, /* request that the canon name be found */
116 noResolve = 0x4000, /* do not attempt to resolve, treat as numeric host */
117
118 streamSocket = 0x8000, /* request a streaming socket (e.g., TCP) */
119 datagramSocket = 0x10000, /* request a datagram socket (e.g., UDP) */
120 rawSocket = 0x20000, /* request a raw socket. This probably requires privileges */
121
122 inputBufferedSocket = 0x200000, /* buffer input in this socket */
123 outputBufferedSocket = 0x400000, /* buffer output in this socket */
124 bufferedSocket = 0x600000 /* make this a fully buffered socket */
125 };
126
132 enum SockStatus
133 {
134 // the numbers are scattered so that we leave room for future expansion
135 error = -1, // invalid status!
136
137 nothing = 0, // no status, the class has just been created
138
139 lookupInProgress = 50, // lookup is in progress. Signals will be sent
140 lookupDone = 70, // lookup has been done. Flags cannot be changed
141 // from this point on
142
143 created = 100, // ::socket() has been called, a socket exists
144 bound = 140, // socket has been bound
145
146 connecting = 200, // socket is connecting (not passiveSocket)
147 connected = 220, // socket has connected (not passiveSocket)
148
149 listening = 200, // socket is listening (passiveSocket)
150 accepting = 220, // socket is accepting (passiveSocket)
151
152 closing = 350, // socket is closing (delayed close)
153
154 done = 400 // socket has been closed
155 };
156
157public:
161 KExtendedSocket();
162
179 KExtendedSocket(const TQString& host, int port, int flags = 0);
180
197 KExtendedSocket(const TQString& host, const TQString& service, int flags = 0);
198
203 virtual ~KExtendedSocket();
204
210 void reset();
211
212 /*
213 * --- status, flags and internal variables --- *
214 */
215
221 int socketStatus() const;
222
229 int systemError() const;
230
236 int setSocketFlags(int flags);
237
243 int socketFlags() const;
244
258 bool setHost(const TQString& host);
259
264 TQString host() const;
265
270 bool setPort(int port);
271
281 bool setPort(const TQString& port);
282
287 TQString port() const;
288
298 bool setAddress(const TQString& host, int port);
299
309 bool setAddress(const TQString& host, const TQString& serv);
310
316 bool setBindHost(const TQString& host);
317
322 bool unsetBindHost();
323
328 TQString bindHost() const;
329
335 bool setBindPort(int port);
336
342 bool setBindPort(const TQString& service);
343
348 bool unsetBindPort();
349
354 TQString bindPort() const;
355
363 bool setBindAddress(const TQString& host, int port);
364
372 bool setBindAddress(const TQString& host, const TQString& service);
373
379 bool unsetBindAddress();
380
392 bool setTimeout(int secs, int usecs = 0);
393
398 timeval timeout() const;
399
408 bool setBlockingMode(bool enable);
409
414 bool blockingMode();
415
425 bool setAddressReusable(bool enable);
426
431 bool addressReusable();
432
451 bool setIPv6Only(bool enable);
452
459 bool isIPv6Only();
460
478 virtual bool setBufferSize(int rsize, int wsize = -2);
479
485 const ::TDESocketAddress *localAddress();
486
493 const ::TDESocketAddress *peerAddress();
494
499 inline int fd() const
500 { return sockfd; }
501
502 /*
503 * -- socket creation -- *
504 */
505
513 virtual int lookup();
514
533 virtual int startAsyncLookup();
534
538 virtual void cancelAsyncLookup();
539
547 virtual int listen(int N = 5); // 5 is arbitrary
548
563 virtual int accept(KExtendedSocket *&sock);
564
588 virtual int connect();
589
604 virtual int startAsyncConnect();
605
609 virtual void cancelAsyncConnect();
610
621 virtual bool open(int mode = (int)(IO_Raw | IO_ReadWrite));
622
630 virtual void close();
631
637 virtual void closeNow();
638
652 virtual void release();
653
654 /*
655 * -- I/O --
656 */
657
673 virtual void flush();
674
679 virtual inline TQ_ULONG size() const
680 { return 0; }
681
686 virtual inline TQ_ULONG at() const
687 { return 0; }
688
694 virtual inline bool at(int i)
695 { Q_UNUSED(i);return true; }
696
702 virtual inline bool atEnd() const
703 { return false; }
704
734 virtual TQ_LONG readBlock(char *data, TQ_ULONG maxlen);
735
759 virtual TQ_LONG writeBlock(const char *data, TQ_ULONG len);
760
775 virtual int peekBlock(char *data, uint maxlen);
776
783 virtual int unreadBlock(const char *data, uint len);
784
794 virtual int bytesAvailable() const;
795
805 virtual int waitForMore(int msec);
806
811 virtual int getch();
812
818 virtual int putch(int ch);
819
824 virtual int ungetch(int)
825 { return -1; }
826
837 virtual void enableRead(bool enable);
838
848 virtual void enableWrite(bool enable);
849
850signals:
856 void lookupFinished(int count);
857
861 void connectionSuccess();
862
868 void connectionFailed(int error);
869
875 void readyAccept();
876
877protected:
878 int sockfd; // file descriptor of the socket
879
880protected slots:
881
882 void socketActivityRead();
883 void socketActivityWrite();
884 void dnsResultsReady();
885 void startAsyncConnectSlot();
886 void connectionEvent();
887
888protected:
889
890 TQSocketNotifier *readNotifier();
891 TQSocketNotifier *writeNotifier();
892
893private:
894
895 // protection against accidental use
896 KExtendedSocket(KExtendedSocket&);
897 KExtendedSocket& operator=(KExtendedSocket&);
898
903 static int doLookup(const TQString& host, const TQString& serv, addrinfo& hint,
904 kde_addrinfo** result);
905
906protected:
910 void setError(int errorkind, int error);
911
912 inline void cleanError()
913 { setError(IO_Ok, 0); }
914
918 void setSocketStatus(int status);
919
920public:
934 static int resolve(sockaddr* sock, ksocklen_t len, TQString& host, TQString& port, int flags = 0) TDE_DEPRECATED;
935
948 static int resolve(::TDESocketAddress* sock, TQString& host, TQString& port, int flags = 0) TDE_DEPRECATED;
949
970 static TQPtrList<KAddressInfo> lookup(const TQString& host, const TQString& port, int flags = 0, int *error = 0) TDE_DEPRECATED;
971
978 static ::TDESocketAddress *localAddress(int fd) TDE_DEPRECATED;
979
987 static ::TDESocketAddress *peerAddress(int fd) TDE_DEPRECATED;
988
995 static TQString strError(int code, int syserr);
996
1006 static bool setAddressReusable(int fd, bool enable) TDE_DEPRECATED;
1007
1008protected:
1009 virtual void virtual_hook( int id, void* data );
1010private:
1011 KExtendedSocketPrivate *d;
1012
1013 friend class TDESocket;
1014 friend class TDEServerSocket;
1015};
1016
1023class TDECORE_EXPORT KAddressInfo
1024{
1025private:
1026 addrinfo *ai;
1027 ::TDESocketAddress *addr;
1028
1029 inline KAddressInfo() : ai(0), addr(0)
1030 { }
1031
1032 // KAddressInfo(addrinfo *ai);
1033 KAddressInfo(KAddressInfo&) { }
1034 KAddressInfo& operator=(KAddressInfo&) { return *this; }
1035
1036public:
1037 ~KAddressInfo();
1038
1043 inline TDE_DEPRECATED operator const ::TDESocketAddress*() const
1044 { return addr; }
1045
1049 inline TDE_DEPRECATED operator const addrinfo&() const
1050 { return *ai; }
1051
1056 inline TDE_DEPRECATED operator const addrinfo*() const
1057 { return ai; }
1058
1064 inline TDE_DEPRECATED const ::TDESocketAddress* address() const
1065 { return addr; }
1066
1071 int flags() const TDE_DEPRECATED;
1072
1077 int family() const TDE_DEPRECATED;
1078
1083 int socktype() const TDE_DEPRECATED;
1084
1089 int protocol() const TDE_DEPRECATED;
1090
1091
1097 const char* canonname() const TDE_DEPRECATED;
1098
1103 inline int length() const
1104 { if (addr) return addr->size(); return 0; }
1105
1106 friend class KExtendedSocket;
1107};
1108
1109#endif //Q_OS_UNIX
1110
1111#endif // KEXTSOCK_H
KAddressInfo
Definition: kextsock.h:1024
KAddressInfo::address
TDE_DEPRECATEDconst ::TDESocketAddress * address() const
Returns the KAddressInfo's TDESocketAddress.
Definition: kextsock.h:1064
KAsyncIO::enableRead
virtual void enableRead(bool enable)=0
Toggles the emission of the readyRead() signal whenever the device is ready for reading.
KAsyncIO::enableWrite
virtual void enableWrite(bool enable)=0
Toggles the emission of the readyWrite() signal whenever the device is ready for writing.
KExtendedSocket
The extended socket class.
Definition: kextsock.h:92
KExtendedSocket::SockStatus
SockStatus
status of the class The status are sequential.
Definition: kextsock.h:133
KExtendedSocket::connectionSuccess
void connectionSuccess()
This signal is emitted whenever we connected asynchronously to a host.
KExtendedSocket::readyAccept
void readyAccept()
This signal is emitted whenever this socket is ready to accept another socket.
KExtendedSocket::connectionFailed
void connectionFailed(int error)
This signal is emitted whenever our asynchronous connection attempt failed to all hosts listed.
KExtendedSocket::size
virtual TQ_ULONG size() const
Returns length of this socket.
Definition: kextsock.h:679
KExtendedSocket::ungetch
virtual int ungetch(int)
Unreads one character from the stream.
Definition: kextsock.h:824
KExtendedSocket::atEnd
virtual bool atEnd() const
Returns true if we are at the end.
Definition: kextsock.h:702
KExtendedSocket::lookupFinished
void lookupFinished(int count)
This signal is emitted whenever an asynchronous lookup process is done.
KExtendedSocket::at
virtual bool at(int i)
Returns true if we are at position.
Definition: kextsock.h:694
KExtendedSocket::fd
int fd() const
Returns the file descriptor.
Definition: kextsock.h:499
KExtendedSocket::at
virtual TQ_ULONG at() const
Returns relative position from start.
Definition: kextsock.h:686
KExtendedSocket::Flags
Flags
flags that can be passed down to the member functions
Definition: kextsock.h:101
TDEBufferedIO
This abstract class implements basic functionality for buffered input/output.
Definition: kbufferedio.h:57
TDEBufferedIO::waitForMore
virtual int waitForMore(int msec)=0
Waits for more data to be available and returns the amount of available data then.
TDEBufferedIO::closeNow
virtual void closeNow()=0
Closes the stream now, discarding the contents of the write buffer.
TDEBufferedIO::unreadBlock
virtual int unreadBlock(const char *data, uint len)
Unreads some data.
Definition: kbufferedio.cpp:155
TDEBufferedIO::setBufferSize
virtual bool setBufferSize(int rsize, int wsize=-2)
Sets the internal buffer size to value.
Definition: kbufferedio.cpp:104
TDEBufferedIO::peekBlock
virtual int peekBlock(char *data, uint maxlen)=0
Reads into the user buffer at most maxlen bytes, but does not consume that data from the read buffer.
TDEBufferedIO::bytesAvailable
virtual int bytesAvailable() const
Returns the number of bytes available for reading in the read buffer.
Definition: kbufferedio.cpp:114
TDEServerSocket
Monitors a port for incoming TCP/IP connections.
Definition: ksock.h:251
TDESocketAddress
A socket address.
Definition: ksockaddr.h:47
TDESocketAddress::size
virtual ksocklen_t size() const
Returns sockaddr structure size.
Definition: ksockaddr.h:85
TDESocket
A TCP/IP client socket.
Definition: ksock.h:88
flush
kndbgstream & flush(kndbgstream &s)
Does nothing.
Definition: kdebug.h:589

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.