Fresco/Prague/include/Prague/IPC Acceptor.hh,1.4,1.5 Agent.hh,1.15,1.16 Connector.hh,1.9,1.10 Coprocess.hh,1.15,1.16 Dispatcher.hh,1.10,1.11 PipeAgent.hh,1.8,1.9 SocketAgent.hh,1.4,1.5 TTYAgent.hh,1.8,1.9 convert.hh,1.3,1.4 ipcbuf.hh,1.16,1.17 mmapbuf.hh,1.5,1.6 pipebuf.hh,1.4,1.5 ptybuf.hh,1.7,1.8 sockbuf.hh,1.15,1.16 sockstream.hh,1.8,1.9
Tobias Hunger <[email protected]> Fri, 31 Oct 2003 22:33:44 +0000
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Prague/include/Prague/IPC In directory purcel:/tmp/cvs-serv28781/Prague/include/Prague/IPC Modified Files: Acceptor.hh Agent.hh Connector.hh Coprocess.hh Dispatcher.hh PipeAgent.hh SocketAgent.hh TTYAgent.hh convert.hh ipcbuf.hh mmapbuf.hh pipebuf.hh ptybuf.hh sockbuf.hh sockstream.hh Log Message: Fix up indention according to the coding style guide. Index: Acceptor.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/Acceptor.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- Acceptor.hh 15 Jan 2001 02:49:18 -0000 1.4 +++ Acceptor.hh 31 Oct 2003 22:33:09 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,47 +27,48 @@ namespace Prague { -//. an Acceptor is an Agent who's responsability is solely -//. to accept connection requests asynchronously. -template <typename Connection> -class Acceptor : public SocketAgent -{ -public: - //. create an Acceptor for the given socket - Acceptor(sockbuf *socket, bool forever = false, size_t queue = 1) - : SocketAgent(socket), _forever(forever), _queue(queue) {} - virtual ~Acceptor() { Trace trace("Acceptor::~Acceptor");} - //. start listening for connection requests - virtual void start(); -private: - //. accept a connection request, and create a new Connection - //. for it. - virtual bool process(int, iomask); - bool _forever; - size_t _queue; -}; + //. an Acceptor is an Agent who's responsability is solely + //. to accept connection requests asynchronously. + template <typename Connection> + class Acceptor : public SocketAgent + { + public: + //. create an Acceptor for the given socket + Acceptor(sockbuf *socket, bool forever = false, size_t queue = 1) : + SocketAgent(socket), _forever(forever), _queue(queue) + { } + virtual ~Acceptor() { Trace trace("Acceptor::~Acceptor"); } + //. start listening for connection requests + virtual void start(); + private: + //. accept a connection request, and create a new Connection + //. for it. + virtual bool process(int, iomask); + bool _forever; + size_t _queue; + }; -template <typename Connection> -void Acceptor<Connection>::start() -{ - Trace trace("Acceptor::start"); - mask(out); - obuf()->listen(_queue); - SocketAgent::start(); -} + template <typename Connection> + void Acceptor<Connection>::start() + { + Trace trace("Acceptor::start"); + mask(out); + obuf()->listen(_queue); + SocketAgent::start(); + } -template <typename Connection> -bool Acceptor<Connection>::process(int, iomask) -{ - Trace trace("Acceptor::process"); - Connection *connection = new Connection(obuf()->accept()); - connection->mask(out); - connection->start(); - connection->remove_ref(); - if (!_forever) stop(); - return _forever; -} + template <typename Connection> + bool Acceptor<Connection>::process(int, iomask) + { + Trace trace("Acceptor::process"); + Connection *connection = new Connection(obuf()->accept()); + connection->mask(out); + connection->start(); + connection->remove_ref(); + if (!_forever) stop(); + return _forever; + } -}; +} // namespace #endif Index: Agent.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/Agent.hh,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Agent.hh 27 Mar 2001 05:38:42 -0000 1.15 +++ Agent.hh 31 Oct 2003 22:33:09 -0000 1.16 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,52 +27,52 @@ namespace Prague { -//. Agents are asynchronous i/o event handlers. Together with the Dispatcher -//. class, they implement the Reactor pattern. -class Agent -{ - friend class Dispatcher; -public: - enum iomask {none = 0x00, outready = 0x01, inready = 0x02, errready = 0x04, - outexc = 0x10, inexc = 0x20, errexc = 0x40, - out = 0x11, in = 0x22, err = 0x44, - asyncio = 0xff}; - Agent(); - virtual ~Agent(); + //. Agents are asynchronous i/o event handlers. Together with the Dispatcher + //. class, they implement the Reactor pattern. + class Agent + { + friend class Dispatcher; + public: + enum iomask {none = 0x00, outready = 0x01, inready = 0x02, errready = 0x04, + outexc = 0x10, inexc = 0x20, errexc = 0x40, + out = 0x11, in = 0x22, err = 0x44, + asyncio = 0xff}; + Agent(); + virtual ~Agent(); - //. bind the Agent to the Dispatcher, which increments the ref counter, and - //. registers the i/o channels as specified with the iomask. - virtual void start(); - //. release the Agent from the Dispatcher, which decrements the ref counter. - virtual void stop(); - bool running() const { return _running;} - //. set a new iomask, to be used by the Dispatcher to determine what events - //. this agent is interested in. - void mask(short); - //. return the current iomask. - short mask() const { return _iomask;} - //. return the buffer referring to the peer's input - i.e. it is an output buffer. - virtual ipcbuf *ibuf() = 0; - //. return the buffer referring to the peer's output - i.e. it is an input buffer. - virtual ipcbuf *obuf() = 0; - //. return the buffer referring to the peer's error - i.e. it is an input buffer. - virtual ipcbuf *ebuf() = 0; - //. increment the ref counter - void add_ref() { ++_refcount;} - //. decrement the ref counter. If the counter becomes zero, the Agent is deleted. - void remove_ref() { if (!--_refcount) delete this;} -private: - Agent(const Agent &); - Agent &operator = (const Agent &); - //. the actual event handler. It is called with the fd on which the event occured, - //. and the iomask telling the kind of event. Overwrite that method in derived classes - //. to implement a specific behavior. - virtual bool process(int, iomask) = 0; - short _refcount; - short _iomask; - bool _running : 1; -}; + //. bind the Agent to the Dispatcher, which increments the ref counter, and + //. registers the i/o channels as specified with the iomask. + virtual void start(); + //. release the Agent from the Dispatcher, which decrements the ref counter. + virtual void stop(); + bool running() const { return _running; } + //. set a new iomask, to be used by the Dispatcher to determine what events + //. this agent is interested in. + void mask(short); + //. return the current iomask. + short mask() const { return _iomask; } + //. return the buffer referring to the peer's input - i.e. it is an output buffer. + virtual ipcbuf *ibuf() = 0; + //. return the buffer referring to the peer's output - i.e. it is an input buffer. + virtual ipcbuf *obuf() = 0; + //. return the buffer referring to the peer's error - i.e. it is an input buffer. + virtual ipcbuf *ebuf() = 0; + //. increment the ref counter + void add_ref() { ++_refcount; } + //. decrement the ref counter. If the counter becomes zero, the Agent is deleted. + void remove_ref() { if (!--_refcount) delete this; } + private: + Agent(const Agent &); + Agent &operator = (const Agent &); + //. the actual event handler. It is called with the fd on which the event occured, + //. and the iomask telling the kind of event. Overwrite that method in derived classes + //. to implement a specific behavior. + virtual bool process(int, iomask) = 0; + short _refcount; + short _iomask; + bool _running : 1; + }; -}; +} // namespace #endif Index: Connector.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/Connector.hh,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Connector.hh 27 Mar 2001 05:38:42 -0000 1.9 +++ Connector.hh 31 Oct 2003 22:33:09 -0000 1.10 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,52 +27,53 @@ namespace Prague { -//. a Connector is an Agent that connects to -//. a specified sockaddr asynchronously -template <typename Connection, typename Socket> -class Connector : public SocketAgent -{ -public: - //. create a Connector for the given sockaddr - Connector(Socket *socket, const typename Socket::address_type &peer) - : SocketAgent(socket), _peer(peer) {} - virtual ~Connector() { Trace trace("Connector::~Connector");} - virtual Socket *ibuf() { return static_cast<Socket *>(SocketAgent::ibuf());} - virtual Socket *obuf() { return static_cast<Socket *>(SocketAgent::obuf());} - //. start with the connection attempt - virtual void start(); -private: - //. if the connection attempt was succesful, create a new Connection for it - virtual bool process(int, iomask); - typename Socket::address_type _peer; -}; + //. a Connector is an Agent that connects to + //. a specified sockaddr asynchronously + template <typename Connection, typename Socket> + class Connector : public SocketAgent + { + public: + //. create a Connector for the given sockaddr + Connector(Socket *socket, const typename Socket::address_type &peer) : + SocketAgent(socket), _peer(peer) + { } + virtual ~Connector() { Trace trace("Connector::~Connector"); } + virtual Socket *ibuf() { return static_cast<Socket *>(SocketAgent::ibuf()); } + virtual Socket *obuf() { return static_cast<Socket *>(SocketAgent::obuf()); } + //. start with the connection attempt + virtual void start(); + private: + //. if the connection attempt was succesful, create a new Connection for it + virtual bool process(int, iomask); + typename Socket::address_type _peer; + }; -template <typename Connection, typename Socket> -void Connector<Connection, Socket>::start() -{ - Trace trace("Connector::start"); - mask(in); - ibuf()->connect(_peer); - SocketAgent::start(); -} + template <typename Connection, typename Socket> + void Connector<Connection, Socket>::start() + { + Trace trace("Connector::start"); + mask(in); + ibuf()->connect(_peer); + SocketAgent::start(); + } -template <typename Connection, typename Socket> -bool Connector<Connection, Socket>::process(int, iomask) -{ - Trace trace("Connector::process"); - int error = ibuf()->clearerror(); - if (!error) - { - stop(); - Connection *connection = new Connection(release_buf()); - connection->mask(out); - connection->start(); - connection->remove_ref(); - } - else std::clog << "connect: " << strerror(error) << std::endl; - return false; -} + template <typename Connection, typename Socket> + bool Connector<Connection, Socket>::process(int, iomask) + { + Trace trace("Connector::process"); + int error = ibuf()->clearerror(); + if (!error) + { + stop(); + Connection *connection = new Connection(release_buf()); + connection->mask(out); + connection->start(); + connection->remove_ref(); + } + else std::clog << "connect: " << strerror(error) << std::endl; + return false; + } -}; +} // namespace #endif Index: Coprocess.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/Coprocess.hh,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- Coprocess.hh 25 Mar 2001 08:25:16 -0000 1.15 +++ Coprocess.hh 31 Oct 2003 22:33:09 -0000 1.16 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -32,74 +32,73 @@ namespace Prague { -//. a Coprocess ia an Agent that spawns a child process and takes care for -//. the associated housekeeping -class Coprocess : public Agent -{ - typedef std::vector<Coprocess *> plist_t; - struct Reaper : Signal::Notifier { virtual void notify(int);}; - friend struct Reaper; -public: - struct IONotifier - { - virtual ~IONotifier(){} - virtual bool notify(iomask) = 0; - }; - struct EOFNotifier + //. a Coprocess ia an Agent that spawns a child process and takes care for + //. the associated housekeeping + class Coprocess : public Agent { - virtual ~EOFNotifier(){} - virtual void notify(iomask) = 0; + typedef std::vector<Coprocess *> plist_t; + struct Reaper : Signal::Notifier { virtual void notify(int);}; + friend struct Reaper; + public: + struct IONotifier + { + virtual ~IONotifier(){} + virtual bool notify(iomask) = 0; + }; + struct EOFNotifier + { + virtual ~EOFNotifier() { } + virtual void notify(iomask) = 0; + }; + enum state_t {ready, running, exited, signaled}; + Coprocess(const std::string &, IONotifier *, EOFNotifier * = 0); + virtual ~Coprocess(); + virtual void start(); + virtual void stop(); + //. return the command of the process being run + const std::string &command() const { return _path;} + //. return the process id of the child process + pid_t pid() const { Prague::Guard<Mutex> guard(_mutex); return _id; } + //. return the state of the child process + state_t state() const { Prague::Guard<Mutex> guard(_mutex); return _state; } + //. return the return value of the child process + int value() const { Prague::Guard<Mutex> guard(_mutex); return _value; } + //. set timeout values used for the terminate call + void timeout(long t, long h, long k) { _timeout.terminate = t, _timeout.hangup = h, _timeout.kill = k; } + virtual ipcbuf *ibuf() { return _inbuf; } + virtual ipcbuf *obuf() { return _outbuf; } + virtual ipcbuf *ebuf() { return _errbuf; } + protected: + virtual bool process(int, iomask); + void terminate(); + void shutdown(int); + std::string _path; + IONotifier *_ioNotifier; + EOFNotifier *_eofNotifier; + pid_t _id; + state_t _state; + int _value; + ipcbuf *_inbuf; + ipcbuf *_outbuf; + ipcbuf *_errbuf; + private: + Coprocess(const Coprocess &); + Coprocess &operator = (const Coprocess &); + bool terminated; + void kill(int); + mutable Mutex _mutex; + struct + { + long hangup; + long terminate; + long kill; + } _timeout; + + static plist_t processes; + static Reaper reaper; + static Mutex singletonMutex; }; - enum state_t {ready, running, exited, signaled}; - Coprocess(const std::string &, IONotifier *, EOFNotifier * = 0); - virtual ~Coprocess(); - virtual void start(); - virtual void stop(); - //. return the command of the process being run - const std::string &command() const { return _path;} - //. return the process id of the child process - pid_t pid() const { Prague::Guard<Mutex> guard(_mutex); return _id;} - //. return the state of the child process - state_t state() const { Prague::Guard<Mutex> guard(_mutex); return _state;} - //. return the return value of the child process - int value() const { Prague::Guard<Mutex> guard(_mutex); return _value;} - //. set timeout values used for the terminate call - void timeout(long t, long h, long k) { _timeout.terminate = t, _timeout.hangup = h, _timeout.kill = k;} - virtual ipcbuf *ibuf() { return _inbuf;} - virtual ipcbuf *obuf() { return _outbuf;} - virtual ipcbuf *ebuf() { return _errbuf;} -protected: - virtual bool process(int, iomask); - void terminate(); - void shutdown(int); -protected: - std::string _path; - IONotifier *_ioNotifier; - EOFNotifier *_eofNotifier; - pid_t _id; - state_t _state; - int _value; - ipcbuf *_inbuf; - ipcbuf *_outbuf; - ipcbuf *_errbuf; -private: - Coprocess(const Coprocess &); - Coprocess &operator = (const Coprocess &); - bool terminated; - void kill(int); - mutable Mutex _mutex; - struct - { - long hangup; - long terminate; - long kill; - } _timeout; - - static plist_t processes; - static Reaper reaper; - static Mutex singletonMutex; -}; -}; +} // namespace #endif Index: Dispatcher.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/Dispatcher.hh,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Dispatcher.hh 8 May 2003 03:21:10 -0000 1.10 +++ Dispatcher.hh 31 Oct 2003 22:33:09 -0000 1.11 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Fresco Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> * http://www.fresco.org * * This library is free software; you can redistribute it and/or @@ -34,67 +34,67 @@ namespace Prague { -//. Dispatcher multiplexes i/o events to registered Agents. Together with -//. the Agents, it implements the Reactor pattern. -//. This implementation uses a thread pool for the actual callbacks. -class Dispatcher -{ -public: - //. Dispatcher being a singleton, return the instance. - static Dispatcher *instance(); - //. bind an Agent to events according to the provided filedescriptor fd, - //. and the mask - void bind(Agent *, int fd, Agent::iomask mask) throw(std::invalid_argument); - //. release an Agent from channel fd, or the whole Agent, if fd is -1 - void release(Agent *, int fd = -1); -private: - typedef std::vector<Agent *> alist_t; - struct task; - typedef std::map<int, task *> repository_t; - //. Handler is responsible for calling a specific method - //. (determined by the mask) on the agent - struct Handler + //. Dispatcher multiplexes i/o events to registered Agents. Together with + //. the Agents, it implements the Reactor pattern. + //. This implementation uses a thread pool for the actual callbacks. + class Dispatcher { - Handler(task *tt) : t(tt) {} - void process() { dispatcher->process(t);} - task *t; - }; - friend struct Handler; - struct Acceptor { Handler *consume(task *t) const { return new Handler(t);}}; - struct Cleaner { ~Cleaner();}; - friend struct Cleaner; - typedef Thread::Queue<task *> Queue; - typedef ThreadPool<task *, Acceptor, Handler> Pool; + public: + //. Dispatcher being a singleton, return the instance. + static Dispatcher *instance(); + //. bind an Agent to events according to the provided filedescriptor fd, + //. and the mask + void bind(Agent *, int fd, Agent::iomask mask) throw(std::invalid_argument); + //. release an Agent from channel fd, or the whole Agent, if fd is -1 + void release(Agent *, int fd = -1); + private: + typedef std::vector<Agent *> alist_t; + struct task; + typedef std::map<int, task *> repository_t; + //. Handler is responsible for calling a specific method + //. (determined by the mask) on the agent + struct Handler + { + Handler(task *tt) : t(tt) {} + void process() { dispatcher->process(t);} + task *t; + }; + friend struct Handler; + struct Acceptor { Handler *consume(task *t) const { return new Handler(t);}}; + struct Cleaner { ~Cleaner();}; + friend struct Cleaner; + typedef Thread::Queue<task *> Queue; + typedef ThreadPool<task *, Acceptor, Handler> Pool; - Dispatcher(); - virtual ~Dispatcher(); - void wait(); - void notify() { char *c = "c"; write(my_wakeup[1], c, 1);} - static void *run(void *); - void dispatch(task *); - void process(task *); - void deactivate(task *); - void activate(task *); + Dispatcher(); + virtual ~Dispatcher(); + void wait(); + void notify() { char *c = "c"; write(my_wakeup[1], c, 1); } + static void *run(void *); + void dispatch(task *); + void process(task *); + void deactivate(task *); + void activate(task *); - static Dispatcher *dispatcher; - static Mutex singletonMutex; - static Cleaner cleaner; + static Dispatcher *dispatcher; + static Mutex singletonMutex; + static Cleaner cleaner; - Mutex my_mutex; - FdSet my_rfds; - FdSet my_wfds; - FdSet my_xfds; - alist_t my_agents; - repository_t my_rchannel; - repository_t my_wchannel; - repository_t my_xchannel; - int my_wakeup[2]; - Queue my_tasks; - Acceptor my_acceptor; - Pool my_workers; - Thread my_server; -}; + Mutex my_mutex; + FdSet my_rfds; + FdSet my_wfds; + FdSet my_xfds; + alist_t my_agents; + repository_t my_rchannel; + repository_t my_wchannel; + repository_t my_xchannel; + int my_wakeup[2]; + Queue my_tasks; + Acceptor my_acceptor; + Pool my_workers; + Thread my_server; + }; -}; +} // namespace #endif Index: PipeAgent.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/PipeAgent.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- PipeAgent.hh 25 Mar 2001 08:25:16 -0000 1.8 +++ PipeAgent.hh 31 Oct 2003 22:33:09 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,19 +27,19 @@ namespace Prague { -//. a PipeAgent uses a pipe to communicate with the coprocess -class PipeAgent : public Coprocess -{ -public: - PipeAgent(const std::string &, IONotifier *, EOFNotifier * = 0); - virtual ~PipeAgent(); - //. spawns a child process after creating a pipe, then redirects i/o to it - virtual void start(); -private: - PipeAgent(const PipeAgent &); - PipeAgent &operator = (const PipeAgent &); -}; + //. A PipeAgent uses a pipe to communicate with the coprocess + class PipeAgent : public Coprocess + { + public: + PipeAgent(const std::string &, IONotifier *, EOFNotifier * = 0); + virtual ~PipeAgent(); + //. spawns a child process after creating a pipe, then redirects i/o to it + virtual void start(); + private: + PipeAgent(const PipeAgent &); + PipeAgent &operator = (const PipeAgent &); + }; -}; +} // namespace #endif Index: SocketAgent.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/SocketAgent.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- SocketAgent.hh 27 Mar 2001 05:38:42 -0000 1.4 +++ SocketAgent.hh 31 Oct 2003 22:33:09 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,25 +28,25 @@ namespace Prague { -//. a SocketAgent is a socket based Agent. It is conceptually lightweight, -//. such that it can be used to generate a pipeline, i.e. similar to the -//. State pattern, SocketAgents can implement a specific strategy in the -//. process method, and then create new SocketAgents for the given socket -//. to get a 'state transition' effect. Since Agents are reference counted, -//. the Dispatcher will take care of deleting them. -class SocketAgent : public Agent -{ -public: - SocketAgent(sockbuf *); - virtual ~SocketAgent(); - virtual sockbuf *ibuf() { return _socket;} - virtual sockbuf *obuf() { return _socket;} - virtual sockbuf *ebuf() { return 0;} - sockbuf *release_buf(); -private: - sockbuf *_socket; -}; + //. a SocketAgent is a socket based Agent. It is conceptually lightweight, + //. such that it can be used to generate a pipeline, i.e. similar to the + //. State pattern, SocketAgents can implement a specific strategy in the + //. process method, and then create new SocketAgents for the given socket + //. to get a 'state transition' effect. Since Agents are reference counted, + //. the Dispatcher will take care of deleting them. + class SocketAgent : public Agent + { + public: + SocketAgent(sockbuf *); + virtual ~SocketAgent(); + virtual sockbuf *ibuf() { return _socket; } + virtual sockbuf *obuf() { return _socket; } + virtual sockbuf *ebuf() { return 0; } + sockbuf *release_buf(); + private: + sockbuf *_socket; + }; -}; +} // namespace #endif Index: TTYAgent.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/TTYAgent.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- TTYAgent.hh 25 Mar 2001 08:25:16 -0000 1.8 +++ TTYAgent.hh 31 Oct 2003 22:33:09 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999, 2000 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -27,23 +27,23 @@ namespace Prague { -//. a Coprocess that uses a tty/pty pair for communication -class TTYAgent : public Coprocess -{ -public: - TTYAgent(const std::string &cmd, IONotifier *, EOFNotifier * = 0); - virtual ~TTYAgent(); - //. spawns a child process after creating a tty/pty pair, then redirects i/o to it - virtual void start(); - //. since the tty preformats the coprocess' output, it needs to - //. know the geometry for the text to fit in - void set_window_size(unsigned short, unsigned short); -private: - TTYAgent(const TTYAgent &); - TTYAgent &operator = (const TTYAgent &); - bool _running; -}; + //. a Coprocess that uses a tty/pty pair for communication + class TTYAgent : public Coprocess + { + public: + TTYAgent(const std::string &cmd, IONotifier *, EOFNotifier * = 0); + virtual ~TTYAgent(); + //. spawns a child process after creating a tty/pty pair, then redirects i/o to it + virtual void start(); + //. since the tty preformats the coprocess' output, it needs to + //. know the geometry for the text to fit in + void set_window_size(unsigned short, unsigned short); + private: + TTYAgent(const TTYAgent &); + TTYAgent &operator = (const TTYAgent &); + bool _running; + }; -}; +} // namespace #endif /* _Prague_TTYAgent_hh */ Index: convert.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/convert.hh,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- convert.hh 16 Jan 2001 01:39:42 -0000 1.3 +++ convert.hh 31 Oct 2003 22:33:09 -0000 1.4 @@ -1,7 +1,7 @@ /*$Id$ * * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * http://www.berlin-consortium.org * * This library is free software; you can redistribute it and/or @@ -27,24 +27,24 @@ namespace Prague { -//. convert t from network to host byte order -template <class T> T net_to_host(const T &t); -//. convert t from host to network byte order -template <class T> T host_to_net(const T &t); + //. convert t from network to host byte order + template <class T> T net_to_host(const T &t); + //. convert t from host to network byte order + template <class T> T host_to_net(const T &t); -int host_to_net<int>(const int &t) { return htonl(t);} -int net_to_host<int>(const int &t) { return ntohl(t);} -long host_to_net<long>(const long &t) { return htonl(t);} -long net_to_host<long>(const long &t) { return ntohl(t);} -short host_to_net<short>(const short &t) { return htons(t);} -short net_to_host<short>(const short &t) { return ntohs(t);} -unsigned int host_to_net<unsigned int>(const unsigned int &t) { return htonl(t);} -unsigned int net_to_host<unsigned int>(const unsigned int &t) { return ntohl(t);} -unsigned long host_to_net<unsigned long>(const unsigned long &t) { return htonl(t);} -unsigned long net_to_host<unsigned long>(const unsigned long &t) { return ntohl(t);} -unsigned short host_to_net<unsigned short>(const unsigned short &t) { return htons(t);} -unsigned short net_to_host<unsigned short>(const unsigned short &t) { return ntohs(t);} + int host_to_net<int>(const int &t) { return htonl(t); } + int net_to_host<int>(const int &t) { return ntohl(t); } + long host_to_net<long>(const long &t) { return htonl(t); } + long net_to_host<long>(const long &t) { return ntohl(t); } + short host_to_net<short>(const short &t) { return htons(t); } + short net_to_host<short>(const short &t) { return ntohs(t); } + unsigned int host_to_net<unsigned int>(const unsigned int &t) { return htonl(t); } + unsigned int net_to_host<unsigned int>(const unsigned int &t) { return ntohl(t); } + unsigned long host_to_net<unsigned long>(const unsigned long &t) { return htonl(t); } + unsigned long net_to_host<unsigned long>(const unsigned long &t) { return ntohl(t); } + unsigned short host_to_net<unsigned short>(const unsigned short &t) { return htons(t); } + unsigned short net_to_host<unsigned short>(const unsigned short &t) { return ntohs(t); } -}; +} // namespace #endif Index: ipcbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/ipcbuf.hh,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- ipcbuf.hh 29 Apr 2003 21:19:10 -0000 1.16 +++ ipcbuf.hh 31 Oct 2003 22:33:09 -0000 1.17 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,71 +28,72 @@ namespace Prague { -//. ipcbuf is a streambuffer for inter process communication, i.e. pipes, sockets, ptys. -//. The low level reading/writing is based on file descriptors. The difference between an -//. ipcbuf and a normal filebuf is the meaning of EOF: in the context of IPC an EOF means -//. that the connection is closed. This case is not handled by the stream but by the -//. corresponding Agent. -//. If the ipcbuf is in nonblocking mode, it returns eof if the underlying read/write -//. causes an EAGAIN error (operation would block). If a real EOF is encountered, a flag -//. is set so the corresponding agent may terminate the process (or reestablish the connection...) -class ipcbuf : public std::streambuf -{ -public: - typedef char char_type; - typedef std::streampos pos_type; - typedef std::streamoff off_type; - typedef int int_type; - typedef std::ios::seekdir seekdir; -public: - //. create a new ipcbuf for the given file descriptor - ipcbuf(int); - virtual ~ipcbuf(); - //. return true if read wouldn't block - bool readready() const; - //. return true if write wouldn't block - bool writeready() const; - bool exceptionpending() const; - //. try to read n bytes into buf, return the number of bytes actually read - virtual std::streamsize sys_read(char *buf, std::streamsize n); - //. try to write n bytes from buf, return the number of bytes actually written - virtual std::streamsize sys_write(const char *buf, std::streamsize n); -// virtual int write (const void *, int); -// virtual int read (void *, int); - //. return the file descriptor for that buffer - int fd() const { return _fd;} - //. set the file descriptor - void fd(int f) { _fd = f;} - bool oob() const { return _oobbit;} - bool oob(bool f) { bool ret = _oobbit; _oobbit = f; return ret;} - //. set the buffer to nonblocking mode if flag is true, to blocking mode otherwise - void async(bool flag); - //. return true if the buffer is in nonblocking mode, false otherwise - bool async() const; - //. did we encounter EOF ? - bool eof() const { return _eofbit;} -// protected: - //. flush the buffer - virtual int sync(); - //. return the number of chars in the input sequence - virtual int showmanyc(); - //. if pbase () == 0, no write is allowed and thus return EOF. - //. if c == EOF, we sync the output and return 0. - //. if pptr () == epptr (), buffer is full and thus sync the output, insert c into buffer, and return c. - virtual int_type overflow(int c = EOF); - virtual int_type underflow(); - virtual int_type uflow(); - virtual int_type pbackfail(int c = EOF); - virtual std::streamsize xsputn(const char *, std::streamsize); - virtual std::streamsize xsgetn(char *, std::streamsize); -private: - int _fd; - int _stmo; // -1==block, 0==poll, >0 == waiting time in secs - int _rtmo; // -1==block, 0==poll, >0 == waiting time in secs - bool _oobbit : 1; // check for out-of-band byte while reading - bool _eofbit : 1; // connection closed -}; + //. ipcbuf is a streambuffer for inter process communication, i.e. pipes, sockets, ptys. + //. The low level reading/writing is based on file descriptors. The difference between an + //. ipcbuf and a normal filebuf is the meaning of EOF: in the context of IPC an EOF means + //. that the connection is closed. This case is not handled by the stream but by the + //. corresponding Agent. + //. If the ipcbuf is in nonblocking mode, it returns eof if the underlying read/write + //. causes an EAGAIN error (operation would block). If a real EOF is encountered, a flag + //. is set so the corresponding agent may terminate the process (or reestablish the connection...) + class ipcbuf : public std::streambuf + { + public: + typedef char char_type; + typedef std::streampos pos_type; + typedef std::streamoff off_type; + typedef int int_type; + typedef std::ios::seekdir seekdir; + public: + //. create a new ipcbuf for the given file descriptor + ipcbuf(int); + virtual ~ipcbuf(); + //. return true if read wouldn't block + bool readready() const; + //. return true if write wouldn't block + bool writeready() const; + bool exceptionpending() const; + //. try to read n bytes into buf, return the number of bytes actually read + virtual std::streamsize sys_read(char *buf, std::streamsize n); + //. try to write n bytes from buf, return the number of bytes actually written + virtual std::streamsize sys_write(const char *buf, std::streamsize n); + // virtual int write (const void *, int); + // virtual int read (void *, int); + //. return the file descriptor for that buffer + int fd() const { return _fd; } + //. set the file descriptor + void fd(int f) { _fd = f; } + bool oob() const { return _oobbit; } + bool oob(bool f) { bool ret = _oobbit; _oobbit = f; return ret; } + //. set the buffer to nonblocking mode if flag is true, to blocking mode otherwise + void async(bool flag); + //. return true if the buffer is in nonblocking mode, false otherwise + bool async() const; + //. did we encounter EOF ? + bool eof() const { return _eofbit; } + // protected: + //. flush the buffer + virtual int sync(); + //. return the number of chars in the input sequence + virtual int showmanyc(); + //. if pbase () == 0, no write is allowed and thus return EOF. + //. if c == EOF, we sync the output and return 0. + //. if pptr () == epptr (), buffer is full and thus sync the output, insert c + //. into buffer, and return c. + virtual int_type overflow(int c = EOF); + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type pbackfail(int c = EOF); + virtual std::streamsize xsputn(const char *, std::streamsize); + virtual std::streamsize xsgetn(char *, std::streamsize); + private: + int _fd; + int _stmo; // -1==block, 0==poll, >0 == waiting time in secs + int _rtmo; // -1==block, 0==poll, >0 == waiting time in secs + bool _oobbit : 1; // check for out-of-band byte while reading + bool _eofbit : 1; // connection closed + }; -} +} // namespace #endif Index: mmapbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/mmapbuf.hh,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- mmapbuf.hh 5 Mar 2003 21:25:25 -0000 1.5 +++ mmapbuf.hh 31 Oct 2003 22:33:09 -0000 1.6 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -29,46 +29,46 @@ namespace Prague { -class mmapbuf : public std::streambuf -//. a streambuf for memory mapped files. -//. since in this context buffering doesn't make sense, -//. the strategy is different: client and server lock -//. a window for reading and writing respectively and -//. shift these windows after reading/writing a block of n characters -{ -public: - typedef char char_type; - typedef std::streampos pos_type; - typedef std::streamoff off_type; - typedef int int_type; - typedef std::ios::seekdir seekdir; + class mmapbuf : public std::streambuf + //. a streambuf for memory mapped files. + //. since in this context buffering doesn't make sense, + //. the strategy is different: client and server lock + //. a window for reading and writing respectively and + //. shift these windows after reading/writing a block of n characters + { + public: + typedef char char_type; + typedef std::streampos pos_type; + typedef std::streamoff off_type; + typedef int int_type; + typedef std::ios::seekdir seekdir; - mmapbuf(int, int); - mmapbuf(const std::string &, size_t, int); - ~mmapbuf(); - bool readready() const; - bool writeready() const; - bool exceptionpending() const; - void setnonblocking(bool); - bool nonblocking() const; -// int write(const void *, int); -// int read(void *, int); -protected: - virtual int sync(); - virtual int showmanyc() const; - virtual int_type overflow(int c = EOF); - virtual int_type underflow(); - virtual int_type uflow(); - virtual int_type pbackfail(int c = EOF); - virtual std::streamsize xsputn(const char *, std::streamsize); - virtual std::streamsize xsgetn(char *, std::streamsize); -private: - mmapbuf(const mmapbuf &); - mmapbuf &operator = (const mmapbuf &); - MMap mmap; - FLock lock; -}; + mmapbuf(int, int); + mmapbuf(const std::string &, size_t, int); + ~mmapbuf(); + bool readready() const; + bool writeready() const; + bool exceptionpending() const; + void setnonblocking(bool); + bool nonblocking() const; + // int write(const void *, int); + // int read(void *, int); + protected: + virtual int sync(); + virtual int showmanyc() const; + virtual int_type overflow(int c = EOF); + virtual int_type underflow(); + virtual int_type uflow(); + virtual int_type pbackfail(int c = EOF); + virtual std::streamsize xsputn(const char *, std::streamsize); + virtual std::streamsize xsgetn(char *, std::streamsize); + private: + mmapbuf(const mmapbuf &); + mmapbuf &operator = (const mmapbuf &); + MMap mmap; + FLock lock; + }; -}; +} // namespace #endif /* _ipcbuf_hh */ Index: pipebuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/pipebuf.hh,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- pipebuf.hh 25 Mar 2001 08:25:16 -0000 1.4 +++ pipebuf.hh 31 Oct 2003 22:33:09 -0000 1.5 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -26,17 +26,17 @@ namespace Prague { -//.a ipcbuf based on a pipe} -class pipebuf : public ipcbuf -{ -public: - pipebuf(int flag) : ipcbuf(flag), fl(flag) {} - //. construct a pipebuf for reading, if @code{mode == ios::in}, writing otherwise - int open(); -protected: - int fl; -}; + //.a ipcbuf based on a pipe} + class pipebuf : public ipcbuf + { + public: + pipebuf(int flag) : ipcbuf(flag), fl(flag) { } + //. construct a pipebuf for reading, if @code{mode == ios::in}, writing otherwise + int open(); + protected: + int fl; + }; -}; +} // namespace #endif /* _pipebuf_hh */ Index: ptybuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/ptybuf.hh,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- ptybuf.hh 2 Jan 2002 12:23:48 -0000 1.7 +++ ptybuf.hh 31 Oct 2003 22:33:09 -0000 1.8 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -28,22 +28,22 @@ namespace Prague { -class ptybuf : public ipcbuf -{ -public: - ptybuf(); - virtual ~ptybuf(); - virtual std::streamsize sys_read(char *, std::streamsize); - const std::string &name() const { return ptydev;} - int openpty(); - int opentty(); - void setup(); -protected: - std::string ptydev; -private: - int tty; -}; + class ptybuf : public ipcbuf + { + public: + ptybuf(); + virtual ~ptybuf(); + virtual std::streamsize sys_read(char *, std::streamsize); + const std::string &name() const { return ptydev;} + int openpty(); + int opentty(); + void setup(); + protected: + std::string ptydev; + private: + int tty; + }; -}; +} // namespace #endif Index: sockbuf.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/sockbuf.hh,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- sockbuf.hh 29 Apr 2003 21:19:10 -0000 1.15 +++ sockbuf.hh 31 Oct 2003 22:33:09 -0000 1.16 @@ -1,9 +1,9 @@ /*$Id$ * - * This source file is a part of the Berlin Project. + * This source file is a part of the Fresco Project. * Copyright (C) 1992-1996 Gnanasekaran Swaminathan <[email protected]> - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * http://www.fresco.org * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,265 +33,263 @@ namespace Prague { -// XXX This #if is ugly! -// NOTE: 'macintosh' is untested, but inferred from Darwin/OSX headers + // XXX This #if is ugly! + // NOTE: 'macintosh' is untested, but inferred from Darwin/OSX headers #if defined(__linux__) || defined(__FreeBSD__) || \ defined(macintosh) || (defined(__APPLE__) && defined(__MACH__)) -# define MSG_MAXIOVLEN 16 +# define MSG_MAXIOVLEN 16 #endif // __linux__ or __FreeBSD__ or macintosh or __APPLE__/__MACH__ -//. socket exception classes -class sockerr -{ -public: - sockerr(int e) : err(e) {} - const char* what() const { return "sockerr";} - int number() const { return err; } - const char *errstr() const; - bool error(int eno) const { return eno == err; } - //. non-blocking and interrupt io recoverable error. - bool io() const; - //. incorrect argument supplied. recoverable error. - bool arg() const; - //. operational error. recovery difficult. - bool op() const; - //. connection error - bool conn() const; - //. address error - bool addr() const; - //. recoverable read/write error like EINTR etc. - bool benign() const; -private: - int err; -}; + //. socket exception classes + class sockerr + { + public: + sockerr(int e) : err(e) { } + const char* what() const { return "sockerr"; } + int number() const { return err; } + const char *errstr() const; + bool error(int eno) const { return eno == err; } + //. non-blocking and interrupt io recoverable error. + bool io() const; + //. incorrect argument supplied. recoverable error. + bool arg() const; + //. operational error. recovery difficult. + bool op() const; + //. connection error + bool conn() const; + //. address error + bool addr() const; + //. recoverable read/write error like EINTR etc. + bool benign() const; + private: + int err; + }; -class sockoob -{ -public: - const char *what() const { return "sockoob";} -}; + class sockoob + { + public: + const char *what() const { return "sockoob";} + }; -//. abstract base for socket addresses} -class sockaddr -{ -public: - virtual ~sockaddr() {} - operator const ::sockaddr *() const { return addr();} - operator ::sockaddr *() { return addr();} - virtual int size() const = 0; - virtual int family() const = 0; - virtual const ::sockaddr *addr() const = 0; - virtual ::sockaddr *addr() = 0; -}; + //. abstract base for socket addresses} + class sockaddr + { + public: + virtual ~sockaddr() { } + operator const ::sockaddr *() const { return addr(); } + operator ::sockaddr *() { return addr(); } + virtual int size() const = 0; + virtual int family() const = 0; + virtual const ::sockaddr *addr() const = 0; + virtual ::sockaddr *addr() = 0; + }; -//. socket unix address representation -class sockunixaddr : public sockaddr_un, public sockaddr -{ -public: - sockunixaddr() {} - sockunixaddr(const std::string &); - sockunixaddr(const sockunixaddr &); - ~sockunixaddr() {} - int size() const { return sizeof (sockaddr_un);} - int family() const { return sun_family;} - const ::sockaddr *addr() const { return reinterpret_cast<const ::sockaddr *>(this);} - ::sockaddr *addr() { return reinterpret_cast< ::sockaddr *>(this);} - const char *path() { return sun_path;} -}; + //. socket unix address representation + class sockunixaddr : public sockaddr_un, public sockaddr + { + public: + sockunixaddr() { } + sockunixaddr(const std::string &); + sockunixaddr(const sockunixaddr &); + ~sockunixaddr() { } + int size() const { return sizeof (sockaddr_un); } + int family() const { return sun_family; } + const ::sockaddr *addr() const { return reinterpret_cast<const ::sockaddr *>(this); } + ::sockaddr *addr() { return reinterpret_cast< ::sockaddr *>(this); } + const char *path() { return sun_path; } + }; -//. socket internet address representation -class sockinetaddr : public sockaddr_in, public sockaddr -{ -public: - sockinetaddr(); - sockinetaddr(unsigned long, int port_no=0); - sockinetaddr(const std::string &, int port_no=0); - sockinetaddr(unsigned long, const std::string &, const std::string &pn = "tcp"); - sockinetaddr(const std::string &, const std::string &, const std::string &pn = "tcp"); - sockinetaddr(const sockinetaddr &); - ~sockinetaddr() {} - int size() const { return sizeof (sockaddr_in);} - int family() const { return sin_family;} - const ::sockaddr *addr() const { return reinterpret_cast<const ::sockaddr *>(this);} - ::sockaddr *addr() { return reinterpret_cast< ::sockaddr *>(this);} - int port() const; - std::string hostname() const; -private: - void port(const std::string &, const std::string &pn = "tcp"); - void addr(const std::string &); -}; + //. socket internet address representation + class sockinetaddr : public sockaddr_in, public sockaddr + { + public: + sockinetaddr(); + sockinetaddr(unsigned long, int port_no=0); + sockinetaddr(const std::string &, int port_no=0); + sockinetaddr(unsigned long, const std::string &, const std::string &pn = "tcp"); + sockinetaddr(const std::string &, const std::string &, const std::string &pn = "tcp"); + sockinetaddr(const sockinetaddr &); + ~sockinetaddr() { } + int size() const { return sizeof (sockaddr_in); } + int family() const { return sin_family; } + const ::sockaddr *addr() const { return reinterpret_cast<const ::sockaddr *>(this); } + ::sockaddr *addr() { return reinterpret_cast< ::sockaddr *>(this); } + int port() const; + std::string hostname() const; + private: + void port(const std::string &, const std::string &pn = "tcp"); + void addr(const std::string &); + }; -struct msghdr; + struct msghdr; -//. an ipcbuf based on a socket -class sockbuf : public ipcbuf -{ -public: - enum domain + //. an ipcbuf based on a socket + class sockbuf : public ipcbuf { - af_unix = AF_UNIX, - af_inet4 = AF_INET, + public: + enum domain + { + af_unix = AF_UNIX, + af_inet4 = AF_INET, #ifdef AF_INET6 - af_inet6 = AF_INET6, + af_inet6 = AF_INET6, #endif #ifdef AF_IPX - af_ipx = AF_IPX, + af_ipx = AF_IPX, #endif #ifdef AF_NETLINK - af_netlink = AF_NETLINK, + af_netlink = AF_NETLINK, #endif #ifdef AF_X25 - af_x25 = AF_X25, + af_x25 = AF_X25, #endif #ifdef AF_AX25 - af_ax25 = AF_AX25, + af_ax25 = AF_AX25, #endif #ifdef AF_ATMPVC - af_atmpvc = AF_ATMPVC, + af_atmpvc = AF_ATMPVC, #endif #ifdef AF_PACKET - af_packet = AF_PACKET, + af_packet = AF_PACKET, #endif - af_appletalk = AF_APPLETALK - }; - enum type - { - sock_stream = SOCK_STREAM, - sock_dgram = SOCK_DGRAM, - sock_raw = SOCK_RAW, - sock_rdm = SOCK_RDM, - sock_seqpacket = SOCK_SEQPACKET - }; - enum option - { - so_debug = SO_DEBUG, - so_reuseaddr = SO_REUSEADDR, - so_keepalive = SO_KEEPALIVE, - so_dontroute = SO_DONTROUTE, - so_broadcast = SO_BROADCAST, - so_linger = SO_LINGER, - so_oobinline = SO_OOBINLINE, - so_sndbuf = SO_SNDBUF, - so_rcvbuf = SO_RCVBUF, - so_error = SO_ERROR, - so_type = SO_TYPE - }; - enum level - { - sol_socket = SOL_SOCKET - }; - enum msgflag - { - msg_oob = MSG_OOB, - msg_peek = MSG_PEEK, - msg_dontroute = MSG_DONTROUTE, - - msg_maxiovlen = MSG_MAXIOVLEN - }; - enum shuthow - { - shut_read, - shut_write, - shut_readwrite - }; - enum { somaxconn = SOMAXCONN }; - struct socklinger - { - int l_onoff; // option on/off - int l_linger; // linger time - socklinger (int a, int b): l_onoff (a), l_linger (b) {} - }; + af_appletalk = AF_APPLETALK + }; + enum type + { + sock_stream = SOCK_STREAM, + sock_dgram = SOCK_DGRAM, + sock_raw = SOCK_RAW, + sock_rdm = SOCK_RDM, + sock_seqpacket = SOCK_SEQPACKET + }; + enum option + { + so_debug = SO_DEBUG, + so_reuseaddr = SO_REUSEADDR, + so_keepalive = SO_KEEPALIVE, + so_dontroute = SO_DONTROUTE, + so_broadcast = SO_BROADCAST, + so_linger = SO_LINGER, + so_oobinline = SO_OOBINLINE, + so_sndbuf = SO_SNDBUF, + so_rcvbuf = SO_RCVBUF, + so_error = SO_ERROR, + so_type = SO_TYPE + }; + enum level + { + sol_socket = SOL_SOCKET + }; + enum msgflag + { + msg_oob = MSG_OOB, + msg_peek = MSG_PEEK, + msg_dontroute = MSG_DONTROUTE, + msg_maxiovlen = MSG_MAXIOVLEN + }; + enum shuthow + { + shut_read, + shut_write, + shut_readwrite + }; + enum { somaxconn = SOMAXCONN }; + struct socklinger + { + int l_onoff; // option on/off + int l_linger; // linger time + socklinger (int a, int b): l_onoff (a), l_linger (b) { } + }; - sockbuf(int s) : ipcbuf(std::ios::in|std::ios::out) { fd(s);} - sockbuf(int, type, int); - virtual ~sockbuf() {} - //. listen for connection requests. Allow up to num requests to be accumulated in the queue - void listen(int num = somaxconn); - //. accept a connection request. Return a new sockbuf for the newly established connection. - virtual sockbuf *accept() = 0; - int read(void *, int); - int recv(void *, int, int msgf = 0); - int recvfrom(sockaddr &, void *, int, int msgf = 0); + sockbuf(int s) : ipcbuf(std::ios::in|std::ios::out) { fd(s); } + sockbuf(int, type, int); + virtual ~sockbuf() { } + //. listen for connection requests. Allow up to num requests to be accumulated in the queue + void listen(int num = somaxconn); + //. accept a connection request. Return a new sockbuf for the newly established connection. + virtual sockbuf *accept() = 0; + int read(void *, int); + int recv(void *, int, int msgf = 0); + int recvfrom(sockaddr &, void *, int, int msgf = 0); #ifndef __linux__ - int recvmsg(msghdr *, int msgf = 0); - int sendmsg(msghdr *, int msgf = 0); + int recvmsg(msghdr *, int msgf = 0); + int sendmsg(msghdr *, int msgf = 0); #endif - int write(const void *, int); - int send(const void *, int, int msgf = 0); - int sendto(sockaddr &, const void *, int, int msgf = 0); - int sendtimeout(int wp = -1); - int recvtimeout(int wp = -1); - void shutdown(shuthow); - int getopt(int, void *, socklen_t, int level = sol_socket) const; - void setopt(int, void *, socklen_t, int level = sol_socket) const; - type gettype () const; - int clearerror () const; - bool debug() const; - bool debug(bool) const; - bool reuseaddr() const; - bool reuseaddr(bool) const; - bool keepalive() const; - bool keepalive(bool) const; - bool dontroute() const; - bool dontroute(bool) const; - bool broadcast() const; - bool broadcast(bool) const; - bool oobinline() const; - bool oobinline(bool) const; - int sendbufsz() const; - int sendbufsz(int) const; - int recvbufsz() const; - int recvbufsz(int) const; - socklinger linger() const; - socklinger linger(socklinger) const; - socklinger linger(int onoff, int tm) const { return linger(socklinger(onoff, tm));} - //. return true, if the read pointer for socket points to an out of band data - bool atmark() const; - //. return the process group id that would receive SIGIO and SIGURG signals - int pgrp() const; - //. set the process group id that would receive SIGIO and SIGURG signals. return the old pgrp - int pgrp(int) const; - void closeonexec(bool set = true) const; - long nread() const; - long howmanyc() const; - void nbio(bool set = true) const; -protected: -}; + int write(const void *, int); + int send(const void *, int, int msgf = 0); + int sendto(sockaddr &, const void *, int, int msgf = 0); + int sendtimeout(int wp = -1); + int recvtimeout(int wp = -1); + void shutdown(shuthow); + int getopt(int, void *, socklen_t, int level = sol_socket) const; + void setopt(int, void *, socklen_t, int level = sol_socket) const; + type gettype () const; + int clearerror () const; + bool debug() const; + bool debug(bool) const; + bool reuseaddr() const; + bool reuseaddr(bool) const; + bool keepalive() const; + bool keepalive(bool) const; + bool dontroute() const; + bool dontroute(bool) const; + bool broadcast() const; + bool broadcast(bool) const; + bool oobinline() const; + bool oobinline(bool) const; + int sendbufsz() const; + int sendbufsz(int) const; + int recvbufsz() const; + int recvbufsz(int) const; + socklinger linger() const; + socklinger linger(socklinger) const; + socklinger linger(int onoff, int tm) const { return linger(socklinger(onoff, tm)); } + //. return true, if the read pointer for socket points to an out of band data + bool atmark() const; + //. return the process group id that would receive SIGIO and SIGURG signals + int pgrp() const; + //. set the process group id that would receive SIGIO and SIGURG signals. return the old pgrp + int pgrp(int) const; + void closeonexec(bool set = true) const; + long nread() const; + long howmanyc() const; + void nbio(bool set = true) const; + }; -//. a sockbuf for the unix domain -class sockunixbuf : public sockbuf -{ -public: - typedef sockunixaddr address_type; - sockunixbuf(int s) : sockbuf(s) {} - sockunixbuf(sockbuf::type ty, int proto = 0) : sockbuf(af_unix, ty, proto) {} - ~sockunixbuf() {} - sockunixaddr addr() const; - void bind(const sockunixaddr &); - virtual sockunixbuf *accept(); - virtual sockunixbuf *accept(sockunixaddr &); - void connect(const sockunixaddr &); -}; + //. a sockbuf for the unix domain + class sockunixbuf : public sockbuf + { + public: + typedef sockunixaddr address_type; + sockunixbuf(int s) : sockbuf(s) { } + sockunixbuf(sockbuf::type ty, int proto = 0) : sockbuf(af_unix, ty, proto) { } + ~sockunixbuf() { } + sockunixaddr addr() const; + void bind(const sockunixaddr &); + virtual sockunixbuf *accept(); + virtual sockunixbuf *accept(sockunixaddr &); + void connect(const sockunixaddr &); + }; -//. a sockbuf for the internet domain -class sockinetbuf : public sockbuf -{ -public: - typedef sockinetaddr address_type; - sockinetbuf (int s) : sockbuf(s) {} - sockinetbuf (sockbuf::type ty, int proto = 0) : sockbuf(af_inet4, ty, proto) {} - ~sockinetbuf () {} - sockinetaddr localaddr() const; - sockinetaddr peeraddr() const; - void bind_until_success (int); - virtual void bind(const sockinetaddr &); - virtual void connect(const sockinetaddr &); - virtual sockinetbuf *accept(); - virtual sockinetbuf *accept(sockinetaddr &); - bool tcpnodelay() const; - bool tcpnodelay(bool set) const; -}; + //. a sockbuf for the internet domain + class sockinetbuf : public sockbuf + { + public: + typedef sockinetaddr address_type; + sockinetbuf(int s) : sockbuf(s) { } + sockinetbuf(sockbuf::type ty, int proto = 0) : sockbuf(af_inet4, ty, proto) { } + ~sockinetbuf() { } + sockinetaddr localaddr() const; + sockinetaddr peeraddr() const; + void bind_until_success(int); + virtual void bind(const sockinetaddr &); + virtual void connect(const sockinetaddr &); + virtual sockinetbuf *accept(); + virtual sockinetbuf *accept(sockinetaddr &); + bool tcpnodelay() const; + bool tcpnodelay(bool set) const; + }; -}; +} // namepace #endif Index: sockstream.hh =================================================================== RCS file: /cvs/fresco/Fresco/Prague/include/Prague/IPC/sockstream.hh,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- sockstream.hh 25 Mar 2001 08:25:16 -0000 1.8 +++ sockstream.hh 31 Oct 2003 22:33:09 -0000 1.9 @@ -1,8 +1,8 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> - * http://www.berlin-consortium.org + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <stefan@frescoorg> + * http://www.fresco.org * * this file is based on code from the socket++ library * Copyright (C) 1992-1996 Gnanasekaran Swaminathan <[email protected]> @@ -31,120 +31,120 @@ namespace Prague { -//. an istream for sockets -class isockstream : public std::istream -{ -public: - isockstream(sockbuf *sb) : std::istream(sb) {} - virtual ~isockstream() {} - sockbuf *rdbuf() { return static_cast<sockbuf *> (std::istream::rdbuf());} - sockbuf *operator ->() { return rdbuf();} -}; + //. an istream for sockets + class isockstream : public std::istream + { + public: + isockstream(sockbuf *sb) : std::istream(sb) { } + virtual ~isockstream() { } + sockbuf *rdbuf() { return static_cast<sockbuf *> (std::istream::rdbuf()); } + sockbuf *operator ->() { return rdbuf(); } + }; -//. an ostream for sockets -class osockstream : public std::ostream -{ -public: - osockstream(sockbuf *sb) : std::ostream(sb) {} - virtual ~osockstream() {} - sockbuf *rdbuf() { return static_cast<sockbuf *> (std::ostream::rdbuf());} - sockbuf *operator ->() { return rdbuf();} -}; + //. an ostream for sockets + class osockstream : public std::ostream + { + public: + osockstream(sockbuf *sb) : std::ostream(sb) { } + virtual ~osockstream() { } + sockbuf *rdbuf() { return static_cast<sockbuf *> (std::ostream::rdbuf()); } + sockbuf *operator ->() { return rdbuf(); } + }; -//. an iostream for sockets -class iosockstream : public std::iostream -{ -public: - iosockstream(sockbuf* sb): std::iostream(sb) {} - virtual ~iosockstream() {} - sockbuf *rdbuf() { return static_cast<sockbuf *> (std::iostream::rdbuf());} - sockbuf *operator ->() { return rdbuf();} -}; + //. an iostream for sockets + class iosockstream : public std::iostream + { + public: + iosockstream(sockbuf* sb): std::iostream(sb) { } + virtual ~iosockstream() { } + sockbuf *rdbuf() { return static_cast<sockbuf *> (std::iostream::rdbuf()); } + sockbuf *operator ->() { return rdbuf(); } + }; -// manipulators -// inline osockstream &crlf (osockstream &o) -// { -// o << "\r\n"; -// o.rdbuf ()->sync (); -// return o; -// } + // manipulators + // inline osockstream &crlf (osockstream &o) + // { + // o << "\r\n"; + // o.rdbuf ()->sync (); + // return o; + // } -// inline osockstream &lfcr (osockstream &o) -// { -// o << "\n\r"; -// o.rdbuf ()->sync (); -// return o; -// } + // inline osockstream &lfcr (osockstream &o) + // { + // o << "\n\r"; + // o.rdbuf ()->sync (); + // return o; + // } -//. an istream for unix sockets -class isockunix : public isockstream -{ -public: - isockunix(int s) : isockstream(new sockunixbuf(s)) {} -// isockunix(const sockunixbuf& sb) : ios (new sockunixbuf (sb)) {} - isockunix(sockbuf::type ty = sockbuf::sock_stream, int proto = 0) : isockstream(new sockunixbuf(ty, proto)) {} - ~isockunix() { delete rdbuf();} - sockunixbuf *operator -> () { return static_cast<sockunixbuf *>(isockstream::rdbuf());} -}; + //. an istream for unix sockets + class isockunix : public isockstream + { + public: + isockunix(int s) : isockstream(new sockunixbuf(s)) { } + // isockunix(const sockunixbuf& sb) : ios (new sockunixbuf (sb)) { } + isockunix(sockbuf::type ty = sockbuf::sock_stream, int proto = 0) : isockstream(new sockunixbuf(ty, proto)) { } + ~isockunix() { delete rdbuf(); } + sockunixbuf *operator -> () { return static_cast<sockunixbuf *>(isockstream::rdbuf()); } + }; -//. an ostream for unix sockets -class osockunix : public osockstream -{ -public: - osockunix(int s) : osockstream(new sockunixbuf(s)) {} -// osockunix (const sockunixbuf& sb) : ios (new sockunixbuf (sb)) {} - osockunix(sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : osockstream(new sockunixbuf(ty, proto)) {} - ~osockunix() { delete rdbuf();} - sockunixbuf *operator -> () { return static_cast<sockunixbuf *> (osockstream::rdbuf());} -}; + //. an ostream for unix sockets + class osockunix : public osockstream + { + public: + osockunix(int s) : osockstream(new sockunixbuf(s)) { } + // osockunix (const sockunixbuf& sb) : ios (new sockunixbuf (sb)) { } + osockunix(sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : osockstream(new sockunixbuf(ty, proto)) { } + ~osockunix() { delete rdbuf(); } + sockunixbuf *operator -> () { return static_cast<sockunixbuf *> (osockstream::rdbuf()); } + }; -//. an iostream for unix sockets -class iosockunix : public iosockstream -{ -public: - iosockunix (int s) : iosockstream(new sockunixbuf(s)) {} -// iosockunix (const sockunixbuf &sb) : ios (new sockunixbuf (sb)) {} - iosockunix (sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : iosockstream(new sockunixbuf(ty, proto)) {} - ~iosockunix () { delete rdbuf();} - sockunixbuf *operator -> () { return static_cast<sockunixbuf *>(iosockstream::rdbuf());} -}; + //. an iostream for unix sockets + class iosockunix : public iosockstream + { + public: + iosockunix (int s) : iosockstream(new sockunixbuf(s)) { } + // iosockunix (const sockunixbuf &sb) : ios (new sockunixbuf (sb)) { } + iosockunix (sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : iosockstream(new sockunixbuf(ty, proto)) { } + ~iosockunix () { delete rdbuf(); } + sockunixbuf *operator -> () { return static_cast<sockunixbuf *>(iosockstream::rdbuf()); } + }; -//. an istream for internet sockets -class isockinet : public isockstream -{ -public: - isockinet (int s) : isockstream(new sockinetbuf(s)) {} -// isockinet (const sockinetbuf &sb) : ios (new sockinetbuf (sb)) {} - isockinet(sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : isockstream(new sockinetbuf(ty, proto)) {} - ~isockinet() { delete rdbuf();} - sockinetbuf *rdbuf() { return static_cast<sockinetbuf *> (isockstream::rdbuf());} - sockinetbuf *operator -> () { return rdbuf();} -}; + //. an istream for internet sockets + class isockinet : public isockstream + { + public: + isockinet (int s) : isockstream(new sockinetbuf(s)) { } + // isockinet (const sockinetbuf &sb) : ios (new sockinetbuf (sb)) { } + isockinet(sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : isockstream(new sockinetbuf(ty, proto)) { } + ~isockinet() { delete rdbuf(); } + sockinetbuf *rdbuf() { return static_cast<sockinetbuf *> (isockstream::rdbuf()); } + sockinetbuf *operator -> () { return rdbuf(); } + }; -//. an ostream for internet sockets -class osockinet : public osockstream -{ -public: - osockinet (int s) : osockstream(new sockinetbuf(s)) {} -// osockinet (const sockinetbuf &sb) : ios(new sockinetbuf(sb)) {} - osockinet (sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : osockstream(new sockinetbuf (ty, proto)) {} - ~osockinet () { delete rdbuf();} - sockinetbuf *rdbuf() { return static_cast<sockinetbuf *> (osockstream::rdbuf());} - sockinetbuf *operator -> () { return rdbuf();} -}; + //. an ostream for internet sockets + class osockinet : public osockstream + { + public: + osockinet (int s) : osockstream(new sockinetbuf(s)) { } + // osockinet (const sockinetbuf &sb) : ios(new sockinetbuf(sb)) { } + osockinet (sockbuf::type ty=sockbuf::sock_stream, int proto = 0) : osockstream(new sockinetbuf (ty, proto)) { } + ~osockinet () { delete rdbuf(); } + sockinetbuf *rdbuf() { return static_cast<sockinetbuf *> (osockstream::rdbuf()); } + sockinetbuf *operator -> () { return rdbuf(); } + }; -//. an iostream for internet sockets -class iosockinet : public iosockstream -{ -public: - iosockinet (int s) : iosockstream(new sockinetbuf(s)) {} -// iosockinet (const sockinetbuf &sb) : ios (new sockinetbuf (sb)) {} - iosockinet (sockbuf::type ty = sockbuf::sock_stream, int proto = 0) : iosockstream(new sockinetbuf(ty, proto)) {} - ~iosockinet () { delete rdbuf();} - sockinetbuf *rdbuf() { return static_cast<sockinetbuf *> (iosockstream::rdbuf());} - sockinetbuf *operator -> () { return rdbuf();} -}; + //. an iostream for internet sockets + class iosockinet : public iosockstream + { + public: + iosockinet (int s) : iosockstream(new sockinetbuf(s)) { } + // iosockinet (const sockinetbuf &sb) : ios (new sockinetbuf (sb)) { } + iosockinet (sockbuf::type ty = sockbuf::sock_stream, int proto = 0) : iosockstream(new sockinetbuf(ty, proto)) { } + ~iosockinet () { delete rdbuf(); } + sockinetbuf *rdbuf() { return static_cast<sockinetbuf *> (iosockstream::rdbuf()); } + sockinetbuf *operator -> () { return rdbuf(); } + }; -}; +} // namespace #endif