|
a/src/netcon.h |
|
b/src/netcon.h |
|
... |
|
... |
15 |
* along with this program; if not, write to the
|
15 |
* along with this program; if not, write to the
|
16 |
* Free Software Foundation, Inc.,
|
16 |
* Free Software Foundation, Inc.,
|
17 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
17 |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
18 |
*/
|
18 |
*/
|
19 |
#include <sys/time.h>
|
19 |
#include <sys/time.h>
|
|
|
20 |
|
20 |
#include <map>
|
21 |
#include <map>
|
21 |
#include <memory>
|
22 |
#include <memory>
|
22 |
|
23 |
#include <string>
|
23 |
|
24 |
|
24 |
/// A set of classes to manage client-server communication over a
|
25 |
/// A set of classes to manage client-server communication over a
|
25 |
/// connection-oriented network, or a pipe.
|
26 |
/// connection-oriented network, or a pipe.
|
26 |
///
|
27 |
///
|
27 |
/// The listening/connection-accepting code currently only uses
|
28 |
/// The listening/connection-accepting code currently only uses
|
|
... |
|
... |
232 |
virtual int doreceive(char *buf, int cnt, int timeo = -1);
|
233 |
virtual int doreceive(char *buf, int cnt, int timeo = -1);
|
233 |
/// Check for data being available for reading
|
234 |
/// Check for data being available for reading
|
234 |
virtual int readready();
|
235 |
virtual int readready();
|
235 |
/// Check for data being available for writing
|
236 |
/// Check for data being available for writing
|
236 |
virtual int writeready();
|
237 |
virtual int writeready();
|
237 |
/// Read a line of text on an ascii connection
|
238 |
/// Read a line of text on an ascii connection. Returns -1 or byte count
|
|
|
239 |
/// including final 0. \n is kept
|
238 |
virtual int getline(char *buf, int cnt, int timeo = -1);
|
240 |
virtual int getline(char *buf, int cnt, int timeo = -1);
|
239 |
/// Set handler to be called when the connection is placed in the
|
241 |
/// Set handler to be called when the connection is placed in the
|
240 |
/// selectloop and an event occurs.
|
242 |
/// selectloop and an event occurs.
|
241 |
virtual void setcallback(std::shared_ptr<NetconWorker> user) {
|
243 |
virtual void setcallback(std::shared_ptr<NetconWorker> user) {
|
242 |
m_user = user;
|
244 |
m_user = user;
|
|
... |
|
... |
256 |
public:
|
258 |
public:
|
257 |
NetconCli(int silent = 0) {
|
259 |
NetconCli(int silent = 0) {
|
258 |
m_silentconnectfailure = silent;
|
260 |
m_silentconnectfailure = silent;
|
259 |
}
|
261 |
}
|
260 |
|
262 |
|
261 |
/// Open connection to specified host and named service.
|
263 |
/// Open connection to specified host and named service. Set host
|
|
|
264 |
/// to an absolute path name for an AF_UNIX service. serv is
|
|
|
265 |
/// ignored in this case.
|
262 |
int openconn(const char *host, char *serv, int timeo = -1);
|
266 |
int openconn(const char *host, const char *serv, int timeo = -1);
|
263 |
|
267 |
|
264 |
/// Open connection to specified host and numeric port. port is in
|
268 |
/// Open connection to specified host and numeric port. port is in
|
265 |
/// HOST byte order
|
269 |
/// HOST byte order. Set host to an absolute path name for an
|
|
|
270 |
/// AF_UNIX service. serv is ignored in this case.
|
266 |
int openconn(const char *host, unsigned int port, int timeo = -1);
|
271 |
int openconn(const char *host, unsigned int port, int timeo = -1);
|
267 |
|
272 |
|
268 |
/// Reuse existing fd.
|
273 |
/// Reuse existing fd.
|
269 |
/// We DONT take ownership of the fd, and do no closin' EVEN on an
|
274 |
/// We DONT take ownership of the fd, and do no closin' EVEN on an
|
270 |
/// explicit closeconn() or setconn() (use getfd(), close,
|
275 |
/// explicit closeconn() or setconn() (use getfd(), close,
|
|
... |
|
... |
309 |
okaddrs.len = okmasks.len = 0;
|
314 |
okaddrs.len = okmasks.len = 0;
|
310 |
okaddrs.intarray = okmasks.intarray = 0;
|
315 |
okaddrs.intarray = okmasks.intarray = 0;
|
311 |
#endif /* NETCON_ACCESSCONTROL */
|
316 |
#endif /* NETCON_ACCESSCONTROL */
|
312 |
}
|
317 |
}
|
313 |
~NetconServLis();
|
318 |
~NetconServLis();
|
314 |
/// Open named service.
|
319 |
/// Open named service. Used absolute pathname to create an
|
|
|
320 |
/// AF_UNIX path-based socket instead of an IP one.
|
315 |
int openservice(char *serv, int backlog = 10);
|
321 |
int openservice(const char *serv, int backlog = 10);
|
316 |
/// Open service by port number.
|
322 |
/// Open service by port number.
|
317 |
int openservice(int port, int backlog = 10);
|
323 |
int openservice(int port, int backlog = 10);
|
318 |
/// Wait for incoming connection. Returned connected Netcon
|
324 |
/// Wait for incoming connection. Returned connected Netcon
|
319 |
NetconServCon *accept(int timeo = -1);
|
325 |
NetconServCon *accept(int timeo = -1);
|
320 |
|
326 |
|
|
... |
|
... |
322 |
/// This should be overriden in a derived class to handle incoming
|
328 |
/// This should be overriden in a derived class to handle incoming
|
323 |
/// connections. It will usually call NetconServLis::accept(), and
|
329 |
/// connections. It will usually call NetconServLis::accept(), and
|
324 |
/// insert the new connection in the selectloop.
|
330 |
/// insert the new connection in the selectloop.
|
325 |
virtual int cando(Netcon::Event reason);
|
331 |
virtual int cando(Netcon::Event reason);
|
326 |
|
332 |
|
|
|
333 |
// Empty if port was numeric, else service name or socket path
|
|
|
334 |
std::string m_serv;
|
|
|
335 |
|
327 |
private:
|
336 |
private:
|
328 |
#ifdef NETCON_ACCESSCONTROL
|
337 |
#ifdef NETCON_ACCESSCONTROL
|
329 |
int permsinit;
|
338 |
int permsinit;
|
330 |
struct intarrayparam okaddrs;
|
339 |
struct intarrayparam okaddrs;
|
331 |
struct intarrayparam okmasks;
|
340 |
struct intarrayparam okmasks;
|
332 |
int initperms(char *servicename);
|
341 |
int initperms(const char *servicename);
|
333 |
int initperms(int port);
|
342 |
int initperms(int port);
|
334 |
int checkperms(void *cli, int clilen);
|
343 |
int checkperms(void *cli, int clilen);
|
335 |
#endif /* NETCON_ACCESSCONTROL */
|
344 |
#endif /* NETCON_ACCESSCONTROL */
|
336 |
};
|
345 |
};
|
337 |
|
346 |
|