~ubuntu-branches/ubuntu/trusty/drizzle/trusty

« back to all changes in this revision

Viewing changes to plugin/pbms/src/cslib/CSSocket.h

  • Committer: Bazaar Package Importer
  • Author(s): Monty Taylor
  • Date: 2010-10-02 14:17:48 UTC
  • mfrom: (1.1.1 upstream)
  • mto: (2.1.17 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20101002141748-m6vbfbfjhrw1153e
Tags: 2010.09.1802-1
* New upstream release.
* Removed pid-file argument hack.
* Updated GPL-2 address to be new address.
* Directly copy in drizzledump.1 since debian doesn't have sphinx 1.0 yet.
* Link to jquery from libjs-jquery. Add it as a depend.
* Add drizzled.8 symlink to the install files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2008 PrimeBase Technologies GmbH, Germany
 
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
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
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
using namespace std;
 
41
 
 
42
class CSOutputStream;
 
43
class CSInputStream;
 
44
 
 
45
class CSSocket : public CSRefObject {
 
46
public:
 
47
        CSSocket() { }
 
48
 
 
49
        virtual ~CSSocket() { }
 
50
 
 
51
        CSOutputStream *getOutputStream();
 
52
 
 
53
        CSInputStream *getInputStream();
 
54
 
 
55
        virtual void formatAddress(size_t size, char *address) = 0;
 
56
 
 
57
        /*
 
58
         * Publish a listener:
 
59
         */
 
60
        virtual void publish(char *service, int default_port) = 0;
 
61
 
 
62
        /*
 
63
         * Accept a connection from a listening socket:
 
64
         */
 
65
        virtual void open(CSSocket *listener) = 0;
 
66
 
 
67
        /*
 
68
         * Connect to a listening socket.
 
69
         */
 
70
        virtual void open(char *address, int default_port) = 0;
 
71
 
 
72
        /*
 
73
         * Close the socket.
 
74
         */
 
75
        virtual void close() { }
 
76
 
 
77
        /*
 
78
         * Read at least one byte from the socket.
 
79
         * This function returns 0 on EOF.
 
80
         * If the function returns at least
 
81
         * one byte, then you must call the function
 
82
         * again, there may be more data available.
 
83
         *
 
84
         * Note: Errors on the socket do not cause
 
85
         * an exception!
 
86
         */
 
87
        virtual size_t read(void *data, size_t size) = 0;
 
88
 
 
89
        /*
 
90
         * Returns -1 on EOF!
 
91
         * Otherwize it returns a character value >= 0
 
92
         * Just like read, error on the socket do
 
93
         * not throw an exception.
 
94
         */
 
95
        virtual int read() = 0;
 
96
 
 
97
        /*
 
98
         * Look at the next character in the file without
 
99
         * taking from the input.
 
100
         */
 
101
        virtual int peek() = 0;
 
102
 
 
103
        /*
 
104
         * Write the given number of bytes.
 
105
         * Throws IOException if an error occurs.
 
106
         */
 
107
        virtual void write(const  void *data, size_t size) = 0;
 
108
 
 
109
        /*
 
110
         * Write a character to the file.
 
111
         */
 
112
        virtual void write(char ch) = 0;
 
113
 
 
114
        /*
 
115
         * Flush the data written.
 
116
         */
 
117
        virtual void flush() = 0;
 
118
 
 
119
        static CSSocket *newSocket();
 
120
 
 
121
        friend class SCSocket;
 
122
 
 
123
private:
 
124
};
 
125
 
 
126
#define CS_SOCKET_ADDRESS_SIZE          300
 
127
 
 
128
class SCSocket : public CSSocket {
 
129
public:
 
130
        SCSocket(): CSSocket(), iHandle(-1), iHost(NULL), iService(NULL), iPort(0) { }
 
131
 
 
132
        virtual ~SCSocket() {
 
133
                close();
 
134
        }
 
135
 
 
136
        virtual void formatAddress(size_t size, char *address);
 
137
 
 
138
        virtual void publish(char *service, int default_port);
 
139
 
 
140
        virtual void open(CSSocket *listener);
 
141
 
 
142
        virtual void open(char *address, int default_port);
 
143
 
 
144
        virtual void close();
 
145
 
 
146
        virtual size_t read(void *data, size_t size);
 
147
 
 
148
        virtual int read();
 
149
 
 
150
        virtual int peek();
 
151
 
 
152
        virtual void write(const void *data, size_t size);
 
153
 
 
154
        virtual void write(char ch);
 
155
 
 
156
        virtual void flush();
 
157
 
 
158
private:
 
159
        void throwError(const char *func, const char *file, int line, char *address, int err);
 
160
        void throwError(const char *func, const char *file, int line, int err);
 
161
        void setInternalOptions();
 
162
        void openInternal();
 
163
 
 
164
        int iHandle;
 
165
        char *iHost;
 
166
        char *iService;
 
167
        int iPort;
 
168
};
 
169
 
 
170
#endif