~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
2234 by Brian Aker
Mass removal of ifdef/endif in favor of pragma once.
29
#pragma once
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
30
#ifndef __CSSOCKET_H__
31
#define __CSSOCKET_H__
32
33
#include <stdio.h>
34
35
#include "CSDefs.h"
36
#include "CSPath.h"
37
#include "CSException.h"
38
#include "CSMemory.h"
39
#include "CSMutex.h"
40
41
class CSOutputStream;
42
class CSInputStream;
43
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
44
#define CS_SOCKET_ADDRESS_SIZE		300
45
46
/* This is only required if you do
47
 * not use an output buffer stream!
48
 */
49
//#define CS_USE_OUTPUT_BUFFER
50
51
#ifdef CS_USE_OUTPUT_BUFFER
52
#ifdef DEBUG
53
#define CS_OUTPUT_BUFFER_SIZE		80
54
#define CS_MIN_WRITE_SIZE			40
55
#else
56
#define CS_OUTPUT_BUFFER_SIZE		(4*1024)
57
#define CS_MIN_WRITE_SIZE			(1500)
58
#endif
59
#endif
60
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
61
class CSSocket : public CSRefObject {
62
public:
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
63
	CSSocket(): iHandle(-1), iHost(NULL), iService(NULL), iIdentity(NULL), iPort(0), iTimeout(0) {
64
#ifdef CS_USE_OUTPUT_BUFFER
65
	iDataLen = 0;
66
#endif
67
	}
68
69
	virtual ~CSSocket() {
70
		close();
71
	}
72
73
	void setTimeout(uint32_t milli_sec);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
74
75
	CSOutputStream *getOutputStream();
76
77
	CSInputStream *getInputStream();
78
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
79
	virtual void formatAddress(size_t size, char *address);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
80
81
	/*
82
	 * Publish a listener:
83
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
84
	virtual void publish(char *service, int default_port);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
85
86
	/*
87
	 * Accept a connection from a listening socket:
88
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
89
	virtual void open(CSSocket *listener);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
90
91
	/*
92
	 * Connect to a listening socket.
93
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
94
	virtual void open(char *address, int default_port);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
95
96
	/*
97
	 * Close the socket.
98
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
99
	virtual void close();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
100
101
	/*
102
	 * Read at least one byte from the socket.
103
	 * This function returns 0 on EOF.
104
	 * If the function returns at least
105
	 * one byte, then you must call the function
106
	 * again, there may be more data available.
107
	 *
108
	 * Note: Errors on the socket do not cause
109
	 * an exception!
110
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
111
	virtual size_t read(void *data, size_t size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
112
113
	/*
114
	 * Returns -1 on EOF!
115
	 * Otherwize it returns a character value >= 0
116
	 * Just like read, error on the socket do
117
	 * not throw an exception.
118
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
119
	virtual int read();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
120
121
	/*
122
	 * Look at the next character in the file without
123
	 * taking from the input.
124
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
125
	virtual int peek();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
126
127
	/*
128
	 * Write the given number of bytes.
129
	 * Throws IOException if an error occurs.
130
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
131
	virtual void write(const  void *data, size_t size);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
132
133
	/*
134
	 * Write a character to the file.
135
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
136
	virtual void write(char ch);
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
137
138
	/*
139
	 * Flush the data written.
140
	 */
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
141
	virtual void flush();
142
143
	virtual const char *identify();
144
145
	static void initSockets();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
146
147
	static CSSocket	*newSocket();
148
149
private:
150
	void throwError(const char *func, const char *file, int line, char *address, int err);
151
	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
152
	void setNoDelay();
153
	void setNonBlocking();
154
	void setBlocking();
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
155
	void openInternal();
1841.1.3 by Barry.Leslie at PrimeBase
Merged changes from lp:pbms. These changes should remove any danger
156
	void writeBlock(const void *data, size_t len);
157
	int timeoutRead(CSThread *self, void *buffer, size_t length);
158
159
	int			iHandle;
160
	char		*iHost;
161
	char		*iService;
162
	char		*iIdentity;
163
	int			iPort;
164
	uint32_t	iTimeout;
165
166
#ifdef CS_USE_OUTPUT_BUFFER
167
	char	iOutputBuffer[CS_OUTPUT_BUFFER_SIZE];
168
	size_t	iDataLen;
169
#endif
170
1548.2.1 by Barry.Leslie at PrimeBase
Added the PBMS daemon plugin.
171
};
172
173
#endif