summaryrefslogtreecommitdiffstats
path: root/libksirtet/lib/socket.h
blob: 01dac72665c7298d8a40f7a78aa0afbc0bcd3251 (plain)
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
#ifndef SOCKET_H
#define SOCKET_H

#include <tqsocketnotifier.h>

#include <kextsock.h>

#include "types.h"


class Socket
{
 public:
 	Socket(KExtendedSocket *, bool createNotifier = FALSE,
		   TQObject *parent = 0, const char *name = 0);

	/** close the socket */
    ~Socket();

	int fd() const { return _socket->fd(); }

    /**
     * Accept a new socket.
     */
    int accept(KExtendedSocket *&);

	/**
	 * @return the socket notifier associated with the socket
	 * (0 if none).
	 */
	TQSocketNotifier *notifier() const { return _notifier; }

	/**
	 * Write data contained in the writing stream to the socket.
	 * It clears the stream.
	 * @return TRUE if all was written without error.
	 */
	bool write();
	bool write(const TQByteArray &a);

	/** @return the TQDataStream for writing. */
	WritingStream &writingStream() { return writing; }

	/** @return the size of pending data. */
	int pendingData() const;

	/**
	 * Read data from socket and append them to reading stream for the specified socket.
	 * The portion of the stream that has been read is cleared.
	 * @return the read size or -1 on error
	 */
	int read();

	/** @return the reading stream. */
	ReadingStream &readingStream() { return reading; }

 private:
    KExtendedSocket *_socket;
	TQSocketNotifier *_notifier;

	WritingStream writing;
	ReadingStream reading;
};

#endif // SOCKET_H