~drizzle-trunk/drizzle/development

1999.6.1 by kalebral at gmail
update Copyright strings to a more common format to help with creating the master debian copyright file
1
/* Copyright (C) 2008 PrimeBase Technologies GmbH, Germany
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
2
 *
3
 * PrimeBase Media Stream for MySQL
4
 *
5
 * This program is free software; you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation; either version 2 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program 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
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
1802.10.2 by Monty Taylor
Update all of the copyright headers to include the correct address.
17
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
18
 *
19
 * Original author: Paul McCullagh (H&G2JCtL)
20
 * Continued development: Barry Leslie
21
 *
22
 * 2007-05-24
23
 *
24
 * CORE SYSTEM:
25
 * Basic file I/O.
26
 *
27
 */
28
29
#ifndef __CSSOCKET_H__
30
#define __CSSOCKET_H__
31
32
#include <stdio.h>
33
34
#include "CSDefs.h"
35
#include "CSPath.h"
36
#include "CSException.h"
37
#include "CSMemory.h"
38
#include "CSMutex.h"
39
40
class CSOutputStream;
41
class CSInputStream;
42
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
43
#define CS_SOCKET_ADDRESS_SIZE		300
44
45
/* This is only required if you do
46
 * not use an output buffer stream!
47
 */
48
//#define CS_USE_OUTPUT_BUFFER
49
50
#ifdef CS_USE_OUTPUT_BUFFER
51
#ifdef DEBUG
52
#define CS_OUTPUT_BUFFER_SIZE		80
53
#define CS_MIN_WRITE_SIZE			40
54
#else
55
#define CS_OUTPUT_BUFFER_SIZE		(4*1024)
56
#define CS_MIN_WRITE_SIZE			(1500)
57
#endif
58
#endif
59
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
60
class CSSocket : public CSRefObject {
61
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
62
	CSSocket(): iHandle(-1), iHost(NULL), iService(NULL), iIdentity(NULL), iPort(0), iTimeout(0) {
63
#ifdef CS_USE_OUTPUT_BUFFER
64
	iDataLen = 0;
65
#endif
66
	}
67
68
	virtual ~CSSocket() {
69
		close();
70
	}
71
72
	void setTimeout(uint32_t milli_sec);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
73
74
	CSOutputStream *getOutputStream();
75
76
	CSInputStream *getInputStream();
77
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
78
	virtual void formatAddress(size_t size, char *address);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
79
80
	/*
81
	 * Publish a listener:
82
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
83
	virtual void publish(char *service, int default_port);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
84
85
	/*
86
	 * Accept a connection from a listening socket:
87
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
88
	virtual void open(CSSocket *listener);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
89
90
	/*
91
	 * Connect to a listening socket.
92
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
93
	virtual void open(char *address, int default_port);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
94
95
	/*
96
	 * Close the socket.
97
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
98
	virtual void close();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
99
100
	/*
101
	 * Read at least one byte from the socket.
102
	 * This function returns 0 on EOF.
103
	 * If the function returns at least
104
	 * one byte, then you must call the function
105
	 * again, there may be more data available.
106
	 *
107
	 * Note: Errors on the socket do not cause
108
	 * an exception!
109
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
110
	virtual size_t read(void *data, size_t size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
111
112
	/*
113
	 * Returns -1 on EOF!
114
	 * Otherwize it returns a character value >= 0
115
	 * Just like read, error on the socket do
116
	 * not throw an exception.
117
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
118
	virtual int read();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
119
120
	/*
121
	 * Look at the next character in the file without
122
	 * taking from the input.
123
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
124
	virtual int peek();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
125
126
	/*
127
	 * Write the given number of bytes.
128
	 * Throws IOException if an error occurs.
129
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
130
	virtual void write(const  void *data, size_t size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
131
132
	/*
133
	 * Write a character to the file.
134
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
135
	virtual void write(char ch);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
136
137
	/*
138
	 * Flush the data written.
139
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
140
	virtual void flush();
141
142
	virtual const char *identify();
143
144
	static void initSockets();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
145
146
	static CSSocket	*newSocket();
147
148
private:
149
	void throwError(const char *func, const char *file, int line, char *address, int err);
150
	void throwError(const char *func, const char *file, int line, int err);
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
151
	void setNoDelay();
152
	void setNonBlocking();
153
	void setBlocking();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
154
	void openInternal();
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
155
	void writeBlock(const void *data, size_t len);
156
	int timeoutRead(CSThread *self, void *buffer, size_t length);
157
158
	int			iHandle;
159
	char		*iHost;
160
	char		*iService;
161
	char		*iIdentity;
162
	int			iPort;
163
	uint32_t	iTimeout;
164
165
#ifdef CS_USE_OUTPUT_BUFFER
166
	char	iOutputBuffer[CS_OUTPUT_BUFFER_SIZE];
167
	size_t	iDataLen;
168
#endif
169
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
170
};
171
172
#endif