Fresco/Prague/src/IPC Agent.cc,1.9,1.10 Coprocess.cc,1.18,1.19 Dispatcher.cc,1.16,1.17 PipeAgent.cc,1.9,1.10 SocketAgent.cc,1.3,1.4 TTYAgent.cc,1.15,1.16 ipcbuf.cc,1.17,1.18 mmapbuf.cc,1.4,1.5 pipebuf.cc,1.5,1.6 ptybuf.cc,1.18,1.19 sockbuf.cc,1.11,1.12
Tobias Hunger <[email protected]> Fri, 31 Oct 2003 22:33:16 +0000
| Newsgroups | gmane.comp.video.fresco.cvs |
|---|---|
| Message-ID | <[email protected]> |
Update of /cvs/fresco/Fresco/Prague/src/IPC In directory purcel:/tmp/cvs-serv28781/Prague/src/IPC Modified Files: Agent.cc Coprocess.cc Dispatcher.cc PipeAgent.cc SocketAgent.cc TTYAgent.cc ipcbuf.cc mmapbuf.cc pipebuf.cc ptybuf.cc sockbuf.cc Log Message: Fix up indention according to the coding style guide. Index: Agent.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/Agent.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- Agent.cc 14 Dec 2000 15:28:19 -0000 1.9 +++ Agent.cc 31 Oct 2003 22:33:12 -0000 1.10 @@ -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 @@ -24,38 +24,38 @@ using namespace Prague; -Agent::Agent() : _refcount(1), _iomask(none), _running(false) {} -Agent::~Agent() {} +Agent::Agent() : _refcount(1), _iomask(none), _running(false) { } +Agent::~Agent() { } void Agent::start() { - _running = true; - if (_iomask & in && ibuf()) Dispatcher::instance()->bind(this, ibuf()->fd(), in); - if (_iomask & out && obuf()) Dispatcher::instance()->bind(this, obuf()->fd(), out); - if (_iomask & err && ebuf()) Dispatcher::instance()->bind(this, ebuf()->fd(), err); + _running = true; + if (_iomask & in && ibuf()) Dispatcher::instance()->bind(this, ibuf()->fd(), in); + if (_iomask & out && obuf()) Dispatcher::instance()->bind(this, obuf()->fd(), out); + if (_iomask & err && ebuf()) Dispatcher::instance()->bind(this, ebuf()->fd(), err); } void Agent::mask(short m) { - if (_iomask == m) return; - if (_running) + if (_iomask == m) return; + if (_running) { - if ((_iomask ^ m) & in) - if (_iomask & in && ibuf()) Dispatcher::instance()->release(this, ibuf()->fd()); - else Dispatcher::instance()->bind(this, ibuf()->fd(), in); - if ((_iomask ^ m) & out) - if (_iomask & out && obuf()) Dispatcher::instance()->release(this, obuf()->fd()); - else Dispatcher::instance()->bind(this, obuf()->fd(), out); - if ((_iomask ^ m) & err) - if (_iomask & err && ebuf()) Dispatcher::instance()->release(this, ebuf()->fd()); - else Dispatcher::instance()->bind(this, ebuf()->fd(), err); + if ((_iomask ^ m) & in) + if (_iomask & in && ibuf()) Dispatcher::instance()->release(this, ibuf()->fd()); + else Dispatcher::instance()->bind(this, ibuf()->fd(), in); + if ((_iomask ^ m) & out) + if (_iomask & out && obuf()) Dispatcher::instance()->release(this, obuf()->fd()); + else Dispatcher::instance()->bind(this, obuf()->fd(), out); + if ((_iomask ^ m) & err) + if (_iomask & err && ebuf()) Dispatcher::instance()->release(this, ebuf()->fd()); + else Dispatcher::instance()->bind(this, ebuf()->fd(), err); } - _iomask = m; + _iomask = m; } void Agent::stop() { - mask(none); - Dispatcher::instance()->release(this); - _running = false; + mask(none); + Dispatcher::instance()->release(this); + _running = false; } Index: Coprocess.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/Coprocess.cc,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- Coprocess.cc 25 Mar 2001 08:25:16 -0000 1.18 +++ Coprocess.cc 31 Oct 2003 22:33:12 -0000 1.19 @@ -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 @@ -46,7 +46,7 @@ Coprocess::Reaper Coprocess::reaper; Mutex Coprocess::singletonMutex; /* - * we can't set the Signal::child handler within the Reapers constructor + * we can't set the Signal::child handler within the Reapers constructor * since Signals are possibly not initialized * do it in the first Coprocess' constructor instead * - stefan @@ -55,133 +55,138 @@ void Coprocess::Reaper::notify(int) { - Trace trace("Coprocess::Reaper::notify"); - Prague::Guard<Mutex> guard(singletonMutex); - for (plist_t::iterator i = processes.begin(); i != processes.end(); i++) + Trace trace("Coprocess::Reaper::notify"); + Prague::Guard<Mutex> guard(singletonMutex); + for (plist_t::iterator i = processes.begin(); i != processes.end(); i++) { - int status; - pid_t id = (*i)->pid(); - if (id > 0 && waitpid(id, &status, 0) == id) - { - if (WIFEXITED(status)) - { - Prague::Guard<Mutex> guard((*i)->_mutex); - (*i)->_id = 0; - (*i)->_state = exited; - (*i)->_value = WEXITSTATUS(status); - } - else if (WIFSIGNALED(status)) - { - Prague::Guard<Mutex> guard((*i)->_mutex); - (*i)->_id = 0; - (*i)->_state = signaled; - (*i)->_value = WTERMSIG(status); - } - processes.erase(i); - break; - } + int status; + pid_t id = (*i)->pid(); + if (id > 0 && waitpid(id, &status, 0) == id) + { + if (WIFEXITED(status)) + { + Prague::Guard<Mutex> guard((*i)->_mutex); + (*i)->_id = 0; + (*i)->_state = exited; + (*i)->_value = WEXITSTATUS(status); + } + else if (WIFSIGNALED(status)) + { + Prague::Guard<Mutex> guard((*i)->_mutex); + (*i)->_id = 0; + (*i)->_state = signaled; + (*i)->_value = WTERMSIG(status); + } + processes.erase(i); + break; + } } } -Coprocess::Coprocess(const std::string &cmd, IONotifier *n, EOFNotifier *e) - : _path(cmd), _ioNotifier(n), _eofNotifier(e), _id(0), _state(ready), _inbuf(0), _outbuf(0), _errbuf(0) +Coprocess::Coprocess(const std::string &cmd, IONotifier *n, EOFNotifier *e) : + _path(cmd), + _ioNotifier(n), + _eofNotifier(e), + _id(0), + _state(ready), + _inbuf(0), + _outbuf(0), + _errbuf(0) { - if (!init) Signal::set(Signal::child, &reaper); - init = true; - _timeout.hangup = 5; - _timeout.terminate = 10; - _timeout.kill = 15; -}; + if (!init) Signal::set(Signal::child, &reaper); + init = true; + _timeout.hangup = 5; + _timeout.terminate = 10; + _timeout.kill = 15; +} Coprocess::~Coprocess() { - stop(); - terminate(); -}; + stop(); + terminate(); +} void Coprocess::start() { - Prague::Guard<Mutex> guard(_mutex); - processes.push_back(this); - _state = running; - Agent::start(); + Prague::Guard<Mutex> guard(_mutex); + processes.push_back(this); + _state = running; + Agent::start(); } void Coprocess::stop() { - Agent::stop(); + Agent::stop(); } bool Coprocess::process(int, iomask m) { - Trace trace("Coprocess::process"); - Prague::Guard<Mutex> guard(_mutex); - /* - * let the client process the IO - */ - bool flag = _ioNotifier ? _ioNotifier->notify(m) : false; - flag &= (_id != 0); - /* - * see whether the channel is still open - */ - switch (m) + Trace trace("Coprocess::process"); + Prague::Guard<Mutex> guard(_mutex); + // let the client process the IO + bool flag = _ioNotifier ? _ioNotifier->notify(m) : false; + flag &= (_id != 0); + // see whether the channel is still open + switch (m) { - case Agent::inready: - case Agent::inexc: - if (ibuf()->eof()) - { - if (_eofNotifier) _eofNotifier->notify(Agent::in); - flag = false; - } - break; - case Agent::outready: - case Agent::outexc: - if (obuf()->eof()) - { - if (_eofNotifier) _eofNotifier->notify(Agent::out); - flag = false; - } - break; - case Agent::errready: - case Agent::errexc: - if (ebuf()->eof()) - { - if (_eofNotifier) _eofNotifier->notify(Agent::err); - flag = false; - } - break; - default: break; + case Agent::inready: + case Agent::inexc: + if (ibuf()->eof()) + { + if (_eofNotifier) _eofNotifier->notify(Agent::in); + flag = false; + } + break; + case Agent::outready: + case Agent::outexc: + if (obuf()->eof()) + { + if (_eofNotifier) _eofNotifier->notify(Agent::out); + flag = false; + } + break; + case Agent::errready: + case Agent::errexc: + if (ebuf()->eof()) + { + if (_eofNotifier) _eofNotifier->notify(Agent::err); + flag = false; + } + break; + default: + break; } - return flag; + return flag; } void Coprocess::terminate() { - int sig = 0; - for (long ms = 0; pid(); ms++) + int sig = 0; + for (long ms = 0; pid(); ms++) { - sig = 0; - if (ms == _timeout.terminate) sig = Signal::terminate; - if (ms == _timeout.hangup) sig = Signal::hangup; - if (ms == _timeout.kill) sig = Signal::kill; - if (sig) kill(sig); - Thread::delay(1); + sig = 0; + if (ms == _timeout.terminate) sig = Signal::terminate; + if (ms == _timeout.hangup) sig = Signal::hangup; + if (ms == _timeout.kill) sig = Signal::kill; + if (sig) kill(sig); + Thread::delay(1); } - Thread::delay(10); - if (pid()) std::cerr << "Coprocess " << pid() << " wouldn't die (" << Signal::name(sig) << ')' << std::endl; + Thread::delay(10); + if (pid()) std::cerr << "Coprocess " << pid() << " wouldn't die (" + << Signal::name(sig) << ')' << std::endl; } void Coprocess::shutdown(int m) { - short om = mask(); - m &= om; - mask(om & ~m); - if (m & in) delete _inbuf, _inbuf = 0; - if (m & out) delete _outbuf, _outbuf = 0; - if (m & err) delete _errbuf, _errbuf = 0; + short om = mask(); + m &= om; + mask(om & ~m); + if (m & in) delete _inbuf, _inbuf = 0; + if (m & out) delete _outbuf, _outbuf = 0; + if (m & err) delete _errbuf, _errbuf = 0; } void Coprocess::kill(int signum) { - if (_id > 0 && ::kill(_id, signum) < 0) std::perror("Coprocess::kill"); + if (_id > 0 && ::kill(_id, signum) < 0) std::perror("Coprocess::kill"); } Index: Dispatcher.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/Dispatcher.cc,v retrieving revision 1.16 retrieving revision 1.17 diff -u -d -r1.16 -r1.17 --- Dispatcher.cc 8 May 2003 03:21:11 -0000 1.16 +++ Dispatcher.cc 31 Oct 2003 22:33:12 -0000 1.17 @@ -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 @@ -37,246 +37,255 @@ struct Dispatcher::task { - task() : fd(-1), agent(0), mask(Agent::none), released(false) {} - task(int ffd, Agent *a, Agent::iomask m) : fd(ffd), agent(a), mask(m) {} - bool operator < (const task &t) const { return fd < t.fd;} - int fd; - Agent *agent; - Agent::iomask mask; - bool released; + task() : fd(-1), agent(0), mask(Agent::none), released(false) {} + task(int ffd, Agent *a, Agent::iomask m) : fd(ffd), agent(a), mask(m) {} + bool operator < (const task &t) const { return fd < t.fd;} + int fd; + Agent *agent; + Agent::iomask mask; + bool released; }; Dispatcher::Cleaner::~Cleaner() { -// Prague::Guard<Mutex> guard(singletonMutex); - delete dispatcher; + // Prague::Guard<Mutex> guard(singletonMutex); + delete dispatcher; } Dispatcher *Dispatcher::instance() { - Prague::Guard<Mutex> guard(singletonMutex); - if (!dispatcher) dispatcher = new Dispatcher; - return dispatcher; + Prague::Guard<Mutex> guard(singletonMutex); + if (!dispatcher) dispatcher = new Dispatcher; + return dispatcher; } -//. create a queue of up to 64 tasks +//. create a queue of up to 64 tasks //. and a thread pool with 16 threads -Dispatcher::Dispatcher() - : my_tasks(64), - my_workers(my_tasks, my_acceptor, 4), - my_server(&Dispatcher::run, this) +Dispatcher::Dispatcher() : + my_tasks(64), + my_workers(my_tasks, my_acceptor, 4), + my_server(&Dispatcher::run, this) { - Signal::mask(Signal::pipe); + Signal::mask(Signal::pipe); } -Dispatcher::~Dispatcher() -{ -} +Dispatcher::~Dispatcher() { } void Dispatcher::bind(Agent *agent, int fd, Agent::iomask mask) throw(std::invalid_argument) { - Trace trace("Dispatcher::bind"); - if (my_server.state() == Thread::READY) - { - pipe(my_wakeup); - my_rfds.set(my_wakeup[0]); - my_server.start(); - } - Prague::Guard<Mutex> guard(my_mutex); - if (find(my_agents.begin(), my_agents.end(), agent) == my_agents.end()) - { - my_agents.push_back(agent); - agent->add_ref(); - } - if (mask & Agent::in) - { - if (mask & Agent::inready) - { - my_wfds.set(fd); - if (my_wchannel.find(fd) == my_wchannel.end()) - my_wchannel[fd] = new task(fd, agent, Agent::inready); - else throw std::invalid_argument("file descriptor already in use"); - } - if (mask & Agent::inexc) + Trace trace("Dispatcher::bind"); + if (my_server.state() == Thread::READY) { - my_xfds.set(fd); - if (my_xchannel.find(fd) == my_xchannel.end()) - my_xchannel[fd] = new task(fd, agent, Agent::inexc); + pipe(my_wakeup); + my_rfds.set(my_wakeup[0]); + my_server.start(); } - } - if (mask & Agent::out) - { - if (mask & Agent::outready) + Prague::Guard<Mutex> guard(my_mutex); + if (find(my_agents.begin(), my_agents.end(), agent) == my_agents.end()) { - my_rfds.set(fd); - if (my_rchannel.find(fd) == my_rchannel.end()) - my_rchannel[fd] = new task(fd, agent, Agent::outready); - else throw std::invalid_argument("file descriptor already in use"); + my_agents.push_back(agent); + agent->add_ref(); } - if (mask & Agent::outexc) + if (mask & Agent::in) { - my_xfds.set(fd); - if (my_xchannel.find(fd) == my_xchannel.end()) - my_xchannel[fd] = new task(fd, agent, Agent::outexc); + if (mask & Agent::inready) + { + my_wfds.set(fd); + if (my_wchannel.find(fd) == my_wchannel.end()) + my_wchannel[fd] = new task(fd, agent, Agent::inready); + else throw std::invalid_argument("file descriptor already in use"); + } + if (mask & Agent::inexc) + { + my_xfds.set(fd); + if (my_xchannel.find(fd) == my_xchannel.end()) + my_xchannel[fd] = new task(fd, agent, Agent::inexc); + } } - } - if (mask & Agent::err) - { - if (mask & Agent::errready) + if (mask & Agent::out) { - my_rfds.set(fd); - if (my_rchannel.find(fd) == my_rchannel.end()) - my_rchannel[fd] = new task(fd, agent, Agent::errready); - else throw std::invalid_argument("file descriptor already in use"); + if (mask & Agent::outready) + { + my_rfds.set(fd); + if (my_rchannel.find(fd) == my_rchannel.end()) + my_rchannel[fd] = new task(fd, agent, Agent::outready); + else throw std::invalid_argument("file descriptor already in use"); + } + if (mask & Agent::outexc) + { + my_xfds.set(fd); + if (my_xchannel.find(fd) == my_xchannel.end()) + my_xchannel[fd] = new task(fd, agent, Agent::outexc); + } } - if (mask & Agent::errexc) + if (mask & Agent::err) { - my_xfds.set(fd); - if (my_xchannel.find(fd) == my_xchannel.end()) - my_xchannel[fd] = new task(fd, agent, Agent::errexc); + if (mask & Agent::errready) + { + my_rfds.set(fd); + if (my_rchannel.find(fd) == my_rchannel.end()) + my_rchannel[fd] = new task(fd, agent, Agent::errready); + else throw std::invalid_argument("file descriptor already in use"); + } + if (mask & Agent::errexc) + { + my_xfds.set(fd); + if (my_xchannel.find(fd) == my_xchannel.end()) + my_xchannel[fd] = new task(fd, agent, Agent::errexc); + } } - } - notify(); + notify(); } void Dispatcher::release(Agent *agent, int fd) { - Trace trace("Dispatcher::release"); - /* - * release file descriptors - */ - Prague::Guard<Mutex> guard(my_mutex); - for (repository_t::iterator i = my_rchannel.begin(); i != my_rchannel.end(); i++) - if ((*i).second->agent == agent && (fd == -1 || fd == (*i).second->fd)) - { - deactivate((*i).second); - (*i).second->released = true; - my_rchannel.erase(i); - } - for (repository_t::iterator i = my_wchannel.begin(); i != my_wchannel.end(); i++) - if ((*i).second->agent == agent && (fd == -1 || fd == (*i).second->fd)) - { - deactivate((*i).second); - (*i).second->released = true; - my_wchannel.erase(i); - } - for (repository_t::iterator i = my_xchannel.begin(); i != my_xchannel.end(); i++) - if ((*i).second->agent == agent && (fd == -1 || fd == (*i).second->fd)) + Trace trace("Dispatcher::release"); + // release file descriptors + Prague::Guard<Mutex> guard(my_mutex); + for (repository_t::iterator i = my_rchannel.begin(); i != my_rchannel.end(); i++) + if ((*i).second->agent == agent && (fd == -1 || fd == (*i).second->fd)) + { + deactivate((*i).second); + (*i).second->released = true; + my_rchannel.erase(i); + } + for (repository_t::iterator i = my_wchannel.begin(); i != my_wchannel.end(); i++) + if ((*i).second->agent == agent && (fd == -1 || fd == (*i).second->fd)) + { + deactivate((*i).second); + (*i).second->released = true; + my_wchannel.erase(i); + } + for (repository_t::iterator i = my_xchannel.begin(); i != my_xchannel.end(); i++) + if ((*i).second->agent == agent && (fd == -1 || fd == (*i).second->fd)) + { + deactivate((*i).second); + (*i).second->released = true; + my_xchannel.erase(i); + } + // release Agent if no more file descriptors left + for (repository_t::iterator i = my_rchannel.begin(); i != my_rchannel.end(); i++) + if ((*i).second->agent == agent) return; + for (repository_t::iterator i = my_wchannel.begin(); i != my_wchannel.end(); i++) + if ((*i).second->agent == agent) return; + for (repository_t::iterator i = my_xchannel.begin(); i != my_xchannel.end(); i++) + if ((*i).second->agent == agent) return; + + alist_t::iterator i = find(my_agents.begin(), my_agents.end(), agent); + if (i != my_agents.end()) { - deactivate((*i).second); - (*i).second->released = true; - my_xchannel.erase(i); + my_agents.erase(i); + agent->remove_ref(); } - /* - * release Agent if no more file descriptors left - */ - for (repository_t::iterator i = my_rchannel.begin(); i != my_rchannel.end(); i++) - if ((*i).second->agent == agent) return; - for (repository_t::iterator i = my_wchannel.begin(); i != my_wchannel.end(); i++) - if ((*i).second->agent == agent) return; - for (repository_t::iterator i = my_xchannel.begin(); i != my_xchannel.end(); i++) - if ((*i).second->agent == agent) return; - - alist_t::iterator i = find(my_agents.begin(), my_agents.end(), agent); - if (i != my_agents.end()) - { - my_agents.erase(i); - agent->remove_ref(); - } } void *Dispatcher::run(void *X) { - Dispatcher *dispatcher = reinterpret_cast<Dispatcher *>(X); - dispatcher->my_workers.start(); - do dispatcher->wait(); - while (true); - return 0; -}; + Dispatcher *dispatcher = reinterpret_cast<Dispatcher *>(X); + dispatcher->my_workers.start(); + do + dispatcher->wait(); + while (true); + return 0; +} void Dispatcher::dispatch(task *t) { - deactivate(t); - my_tasks.push(t); + deactivate(t); + my_tasks.push(t); } void Dispatcher::process(task *t) { - Trace trace("Dispatcher::process"); - Agent *agent = t->agent; - // save the agent from being deleted while it processes i/o - agent->add_ref(); - bool done = !agent->process(t->fd, t->mask); - agent->remove_ref(); - // now look whether the agent is released and the task should be deleted - Prague::Guard<Mutex> guard(my_mutex); - if (!done) - { - if (t->released) delete t; - else activate(t); - } + Trace trace("Dispatcher::process"); + Agent *agent = t->agent; + // save the agent from being deleted while it processes i/o + agent->add_ref(); + bool done = !agent->process(t->fd, t->mask); + agent->remove_ref(); + // now look whether the agent is released and the task should be deleted + Prague::Guard<Mutex> guard(my_mutex); + if (!done) + { + if (t->released) delete t; + else activate(t); + } } void Dispatcher::deactivate(task *t) { - switch (t->mask) - { - case Agent::inready: my_wfds.clear(t->fd); break; - case Agent::outready: - case Agent::errready: my_rfds.clear(t->fd); break; - case Agent::inexc: - case Agent::outexc: - case Agent::errexc: my_xfds.clear(t->fd); break; - default: break; - } + switch (t->mask) + { + case Agent::inready: + my_wfds.clear(t->fd); + break; + case Agent::outready: + case Agent::errready: + my_rfds.clear(t->fd); + break; + case Agent::inexc: + case Agent::outexc: + case Agent::errexc: + my_xfds.clear(t->fd); + break; + default: + break; + } } void Dispatcher::activate(task *t) { - switch (t->mask) - { - case Agent::inready: my_wfds.set(t->fd); break; - case Agent::outready: - case Agent::errready: my_rfds.set(t->fd); break; - case Agent::inexc: - case Agent::outexc: - case Agent::errexc: my_xfds.set(t->fd); break; - default: break; - } - notify(); + switch (t->mask) + { + case Agent::inready: + my_wfds.set(t->fd); + break; + case Agent::outready: + case Agent::errready: + my_rfds.set(t->fd); + break; + case Agent::inexc: + case Agent::outexc: + case Agent::errexc: + my_xfds.set(t->fd); + break; + default: + break; + } + notify(); } void Dispatcher::wait() { - Trace trace("Dispatcher::wait"); - FdSet tmprfds = my_rfds; - FdSet tmpwfds = my_wfds; - FdSet tmpxfds = my_xfds; - unsigned int fdsize = std::max(std::max(tmprfds.max(), tmpwfds.max()), - tmpxfds.max()) + 1; - int nsel = select(fdsize, tmprfds, tmpwfds, tmpxfds, 0); - Thread::testcancel(); - if (nsel == -1) - { - if (errno == EINTR || errno == EAGAIN) errno = 0; - } - else if (nsel > 0 && fdsize) - { - Prague::Guard<Mutex> guard(my_mutex); - for (repository_t::iterator i = my_rchannel.begin(); i != my_rchannel.end(); i++) - if (tmprfds.isset((*i).first)) - dispatch((*i).second); - for (repository_t::iterator i = my_wchannel.begin(); i != my_wchannel.end(); i++) - if (tmpwfds.isset((*i).first)) - dispatch((*i).second); - for (repository_t::iterator i = my_xchannel.begin(); i != my_xchannel.end(); i++) - if (tmpxfds.isset((*i).first)) - dispatch((*i).second); - if (tmprfds.isset(my_wakeup[0])) + Trace trace("Dispatcher::wait"); + FdSet tmprfds = my_rfds; + FdSet tmpwfds = my_wfds; + FdSet tmpxfds = my_xfds; + unsigned int fdsize = std::max(std::max(tmprfds.max(), tmpwfds.max()), + tmpxfds.max()) + 1; + int nsel = select(fdsize, tmprfds, tmpwfds, tmpxfds, 0); + Thread::testcancel(); + if (nsel == -1) { - char c[1]; - read(my_wakeup[0], c, 1); + if (errno == EINTR || errno == EAGAIN) errno = 0; + } + else if (nsel > 0 && fdsize) + { + Prague::Guard<Mutex> guard(my_mutex); + for (repository_t::iterator i = my_rchannel.begin(); i != my_rchannel.end(); i++) + if (tmprfds.isset((*i).first)) + dispatch((*i).second); + for (repository_t::iterator i = my_wchannel.begin(); i != my_wchannel.end(); i++) + if (tmpwfds.isset((*i).first)) + dispatch((*i).second); + for (repository_t::iterator i = my_xchannel.begin(); i != my_xchannel.end(); i++) + if (tmpxfds.isset((*i).first)) + dispatch((*i).second); + if (tmprfds.isset(my_wakeup[0])) + { + char c[1]; + read(my_wakeup[0], c, 1); + } } - } } Index: PipeAgent.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/PipeAgent.cc,v retrieving revision 1.9 retrieving revision 1.10 diff -u -d -r1.9 -r1.10 --- PipeAgent.cc 25 Mar 2001 08:25:16 -0000 1.9 +++ PipeAgent.cc 31 Oct 2003 22:33:12 -0000 1.10 @@ -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,57 +27,54 @@ using namespace Prague; -PipeAgent::PipeAgent(const std::string &cmd, IONotifier *io, EOFNotifier *eof) - : Coprocess(cmd, io, eof) -{} +PipeAgent::PipeAgent(const std::string &cmd, IONotifier *io, EOFNotifier *eof) : + Coprocess(cmd, io, eof) +{ } -PipeAgent::~PipeAgent() -{ - shutdown(in|out|err); -} +PipeAgent::~PipeAgent() { shutdown(in|out|err); } void PipeAgent::start() { - if (_id >= 0) + if (_id >= 0) { - terminate(); - pipebuf *pin = new pipebuf(std::ios::out); // the stdin for the child is an output stream for the parent... - pipebuf *pout = new pipebuf(std::ios::in); // the stdout for the child is an input stream for the parent... - pipebuf *perr = new pipebuf(std::ios::in); // the stderr for the child is an input stream for the parent... - int fin = pin->open(); - int fout = pout->open(); - int ferr = perr->open(); -// if (fin == -1 || fout == -1 || ferr == -1) { Error("communication setup failed", true); return;} - switch(_id = fork()) - { - case -1: - _id = 0; -// SystemError("cannot fork", true); - return; - case 0: - dup2(fin, fileno(stdin)); close(fin); - dup2(fout, fileno(stdout)); close(fout); - dup2(ferr, fileno(stderr)); close(ferr); - const char *argv[4]; - argv[0] = "/bin/sh"; - argv[1] = "-c"; - argv[2] = _path.c_str(); - argv[3] = 0; - execvp ("/bin/sh", (char**) argv); - std::perror("/bin/sh"); - _exit(EXIT_FAILURE); - break; - default: - _inbuf = pin; close(fin); - _outbuf = pout; close(fout); - _errbuf = perr; close(ferr); - _inbuf->async(true); - _outbuf->async(true); - _errbuf->async(true); - break; - } + terminate(); + pipebuf *pin = new pipebuf(std::ios::out); // the stdin for the child is an output stream for the parent... + pipebuf *pout = new pipebuf(std::ios::in); // the stdout for the child is an input stream for the parent... + pipebuf *perr = new pipebuf(std::ios::in); // the stderr for the child is an input stream for the parent... + int fin = pin->open(); + int fout = pout->open(); + int ferr = perr->open(); + // if (fin == -1 || fout == -1 || ferr == -1) { Error("communication setup failed", true); return;} + switch(_id = fork()) + { + case -1: + _id = 0; + // SystemError("cannot fork", true); + return; + case 0: + dup2(fin, fileno(stdin)); close(fin); + dup2(fout, fileno(stdout)); close(fout); + dup2(ferr, fileno(stderr)); close(ferr); + const char *argv[4]; + argv[0] = "/bin/sh"; + argv[1] = "-c"; + argv[2] = _path.c_str(); + argv[3] = 0; + execvp ("/bin/sh", (char**) argv); + std::perror("/bin/sh"); + _exit(EXIT_FAILURE); + break; + default: + _inbuf = pin; close(fin); + _outbuf = pout; close(fout); + _errbuf = perr; close(ferr); + _inbuf->async(true); + _outbuf->async(true); + _errbuf->async(true); + break; + } } -// mask(in|out|err); - mask(out|err); - Coprocess::start(); -}; + // mask(in|out|err); + mask(out|err); + Coprocess::start(); +} Index: SocketAgent.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/SocketAgent.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- SocketAgent.cc 27 Mar 2001 05:38:42 -0000 1.3 +++ SocketAgent.cc 31 Oct 2003 22:33:12 -0000 1.4 @@ -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 @@ -25,23 +25,23 @@ using namespace Prague; -SocketAgent::SocketAgent(sockbuf *socket) - : _socket(socket) +SocketAgent::SocketAgent(sockbuf *socket) : + _socket(socket) { - Trace trace("SocketAgent::SocketAgent"); - _socket->async(true); + Trace trace("SocketAgent::SocketAgent"); + _socket->async(true); } SocketAgent::~SocketAgent() { - Trace trace("SocketAgent::~SocketAgent"); - delete _socket; + Trace trace("SocketAgent::~SocketAgent"); + delete _socket; } sockbuf *SocketAgent::release_buf() { - stop(); - sockbuf *s = _socket; - _socket = 0; - return s; + stop(); + sockbuf *s = _socket; + _socket = 0; + return s; } Index: TTYAgent.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/TTYAgent.cc,v retrieving revision 1.15 retrieving revision 1.16 diff -u -d -r1.15 -r1.16 --- TTYAgent.cc 29 Nov 2002 21:15:00 -0000 1.15 +++ TTYAgent.cc 31 Oct 2003 22:33:12 -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,72 +27,72 @@ using namespace Prague; -TTYAgent::TTYAgent(const std::string &cmd, IONotifier *io, EOFNotifier *eof) - : Coprocess(cmd, io, eof) -{} +TTYAgent::TTYAgent(const std::string &cmd, IONotifier *io, EOFNotifier *eof) : + Coprocess(cmd, io, eof) +{ } TTYAgent::~TTYAgent() { - stop(); - shutdown(in|out|err); + stop(); + shutdown(in|out|err); } void TTYAgent::start() { - Trace trace("TTYAgent::start"); - if (pid() >= 0) + Trace trace("TTYAgent::start"); + if (pid() >= 0) { - terminate(); - ptybuf *pty = new ptybuf; - int fd = pty->openpty(); - switch(_id = fork()) - { - case -1: - _id = 0; -// SystemError("cannot fork", true); - return; - case 0: - { - // Set this (child) process to be its own process group leader - // This allows the shell to implement job control properly - // FIXME: portability of this function is uncertain - setpgid(0, 0); - int fds = pty->opentty(); - if (fds < 0) _exit(EXIT_FAILURE); - close(fd); - dup2(fds, fileno(stdin)); - dup2(fds, fileno(stdout)); - dup2(fds, fileno(stderr)); - if (fds > fileno(stderr)) close(fds); - const char *argv[4]; - argv[0] = "/bin/sh"; - argv[1] = "-c"; - argv[2] = _path.c_str(); - argv[3] = 0; - execvp ("/bin/sh", (char**) argv); - perror("/bin/sh"); - _exit(EXIT_FAILURE); + terminate(); + ptybuf *pty = new ptybuf; + int fd = pty->openpty(); + switch(_id = fork()) + { + case -1: + _id = 0; + // SystemError("cannot fork", true); + return; + case 0: + { + // Set this (child) process to be its own process group leader + // This allows the shell to implement job control properly + // FIXME: portability of this function is uncertain + setpgid(0, 0); + int fds = pty->opentty(); + if (fds < 0) _exit(EXIT_FAILURE); + close(fd); + dup2(fds, fileno(stdin)); + dup2(fds, fileno(stdout)); + dup2(fds, fileno(stderr)); + if (fds > fileno(stderr)) close(fds); + const char *argv[4]; + argv[0] = "/bin/sh"; + argv[1] = "-c"; + argv[2] = _path.c_str(); + argv[3] = 0; + execvp ("/bin/sh", (char**) argv); + perror("/bin/sh"); + _exit(EXIT_FAILURE); + break; + } + default: + _inbuf = _outbuf = pty; + _errbuf = 0; + _inbuf->async(true); break; - } - default: - _inbuf = _outbuf = pty; - _errbuf = 0; - _inbuf->async(true); - break; - } + } } - _running = true; - mask(out); - Coprocess::start(); -}; + _running = true; + mask(out); + Coprocess::start(); +} void TTYAgent::set_window_size(unsigned short columns, unsigned short rows) { #if defined(HAVE_IOCTL) - struct winsize ws; - ws.ws_col = columns; - ws.ws_row = rows; - ws.ws_xpixel = ws.ws_ypixel = 0; - if (ioctl (master, TIOCSWINSZ, &ws) != 0); + struct winsize ws; + ws.ws_col = columns; + ws.ws_row = rows; + ws.ws_xpixel = ws.ws_ypixel = 0; + if (ioctl (master, TIOCSWINSZ, &ws) != 0); #endif -}; +} Index: ipcbuf.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/ipcbuf.cc,v retrieving revision 1.17 retrieving revision 1.18 diff -u -d -r1.17 -r1.18 --- ipcbuf.cc 29 Apr 2003 21:19:11 -0000 1.17 +++ ipcbuf.cc 31 Oct 2003 22:33:12 -0000 1.18 @@ -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 @@ -34,179 +34,189 @@ using namespace Prague; -ipcbuf::ipcbuf(int mode) - : _fd(-1), _stmo(-1), _rtmo(-1), _oobbit(false), _eofbit(false) +ipcbuf::ipcbuf(int mode) : + _fd(-1), + _stmo(-1), + _rtmo(-1), + _oobbit(false), + _eofbit(false) { - Trace trace("ipcbuf::ipcbuf"); - if (mode & std::ios::in) + Trace trace("ipcbuf::ipcbuf"); + if (mode & std::ios::in) { - char_type *gbuf = new char_type [BUFSIZ]; - setg(gbuf, gbuf + BUFSIZ, gbuf + BUFSIZ); + char_type *gbuf = new char_type [BUFSIZ]; + setg(gbuf, gbuf + BUFSIZ, gbuf + BUFSIZ); } - if (mode & std::ios::out) + if (mode & std::ios::out) { - char_type *pbuf = new char_type [BUFSIZ]; - setp(pbuf, pbuf + BUFSIZ); + char_type *pbuf = new char_type [BUFSIZ]; + setp(pbuf, pbuf + BUFSIZ); } } ipcbuf::~ipcbuf() { - Trace trace("ipcbuf::~ipcbuf"); - overflow(EOF); // flush write buffer - delete [] pbase(); - delete [] eback(); - if (fd() != -1 && close(fd()) == -1) perror("ipcbuf::~ipcbuf"); + Trace trace("ipcbuf::~ipcbuf"); + overflow(EOF); // flush write buffer + delete [] pbase(); + delete [] eback(); + if (fd() != -1 && close(fd()) == -1) perror("ipcbuf::~ipcbuf"); } bool ipcbuf::readready() const { - FdSet fds; - fds.set(fd()); - Time T; - if (select(fds.max() + 1, fds, 0, 0, &T) == 0) return true; - return false; + FdSet fds; + fds.set(fd()); + Time T; + if (select(fds.max() + 1, fds, 0, 0, &T) == 0) return true; + return false; } bool ipcbuf::writeready() const { - FdSet fds; - fds.set(fd()); - Time T; - if (select(fds.max() + 1, 0, fds, 0, &T) == 0) return true; - return false; + FdSet fds; + fds.set(fd()); + Time T; + if (select(fds.max() + 1, 0, fds, 0, &T) == 0) return true; + return false; } bool ipcbuf::exceptionpending() const { - FdSet fds; - fds.set(fd()); - Time T; - if (select(fds.max() + 1, 0, 0, fds, &T) == 0) return true; - return false; + FdSet fds; + fds.set(fd()); + Time T; + if (select(fds.max() + 1, 0, 0, fds, &T) == 0) return true; + return false; } void ipcbuf::async(bool flag) { - int flags = fcntl(fd(), F_GETFL); - if (flag) flags |= O_NONBLOCK; - else flags &= ~(O_NONBLOCK); - fcntl(fd(), F_SETFL, flags); + int flags = fcntl(fd(), F_GETFL); + if (flag) flags |= O_NONBLOCK; + else flags &= ~(O_NONBLOCK); + fcntl(fd(), F_SETFL, flags); } bool ipcbuf::async() const { - int flags = fcntl(fd(), F_GETFL); - return flags | O_NONBLOCK; + int flags = fcntl(fd(), F_GETFL); + return flags | O_NONBLOCK; } int ipcbuf::sync() { - if (pptr() && pbase() < pptr() && pptr() <= epptr()) + if (pptr() && pbase() < pptr() && pptr() <= epptr()) { - sys_write(pbase(), pptr() - pbase()); - setp(pbase(), pbase() + BUFSIZ); + sys_write(pbase(), pptr() - pbase()); + setp(pbase(), pbase() + BUFSIZ); } - return 0; + return 0; } int ipcbuf::showmanyc() { - if (gptr() && gptr() < egptr()) return egptr() - gptr(); - return 0; + if (gptr() && gptr() < egptr()) return egptr() - gptr(); + return 0; } ipcbuf::int_type ipcbuf::overflow(int c) { - if (pbase() == 0) return EOF; - if (c == EOF) return sync(); - if (pptr() == epptr()) sync(); - *pptr() = (char_type) c; - pbump(1); - return c; + if (pbase() == 0) return EOF; + if (c == EOF) return sync(); + if (pptr() == epptr()) sync(); + *pptr() = (char_type) c; + pbump(1); + return c; } ipcbuf::int_type ipcbuf::underflow() { - if (gptr() == 0) return EOF; // input stream has been disabled - if (gptr() < egptr()) return *gptr(); - ssize_t rlen = sys_read(eback(), BUFSIZ); - switch (rlen) + if (gptr() == 0) return EOF; // input stream has been disabled + if (gptr() < egptr()) return *gptr(); + ssize_t rlen = sys_read(eback(), BUFSIZ); + switch (rlen) { - case 0: _eofbit = true; - case EOF: return EOF; - default: setg(eback(), eback(), eback() + rlen); return *gptr(); + case 0: + _eofbit = true; + case EOF: + return EOF; + default: + setg(eback(), eback(), eback() + rlen); + return *gptr(); } } ipcbuf::int_type ipcbuf::uflow() { - int_type ret = underflow(); - if (ret == EOF) return EOF; - gbump(1); - return ret; + int_type ret = underflow(); + if (ret == EOF) return EOF; + gbump(1); + return ret; } ipcbuf::int_type ipcbuf::pbackfail(int c) { - return EOF; + return EOF; } std::streamsize ipcbuf::xsputn(const ipcbuf::char_type *s, std::streamsize n) { - int wval = epptr() - pptr(); - if (n <= wval) + int wval = epptr() - pptr(); + if (n <= wval) { - Memory::copy(s, pptr(), n * sizeof(char_type)); - pbump(n); - return n; + Memory::copy(s, pptr(), n * sizeof(char_type)); + pbump(n); + return n; } - Memory::copy(s, pptr(), wval * sizeof(char_type)); - pbump(wval); - if (overflow() != EOF) return wval + xsputn(s + wval, n - wval); - return wval; + Memory::copy(s, pptr(), wval * sizeof(char_type)); + pbump(wval); + if (overflow() != EOF) return wval + xsputn(s + wval, n - wval); + return wval; } std::streamsize ipcbuf::xsgetn(ipcbuf::char_type *s, std::streamsize n) { - int rval = showmanyc (); - if (rval >= n) + int rval = showmanyc(); + if (rval >= n) { - Memory::copy(gptr(), s, n * sizeof(char_type)); - gbump(n); - return n; + Memory::copy(gptr(), s, n * sizeof(char_type)); + gbump(n); + return n; } - Memory::copy(gptr(), s, rval * sizeof(char_type)); - gbump(rval); - if (underflow() != EOF) return rval + xsgetn(s + rval, n - rval); - return rval; + Memory::copy(gptr(), s, rval * sizeof(char_type)); + gbump(rval); + if (underflow() != EOF) return rval + xsgetn(s + rval, n - rval); + return rval; } std::streamsize ipcbuf::sys_write(const char *buf, std::streamsize len) { -// if (!writeready ()) return 0; - std::streamsize wlen = 0; - while(len > 0) + // if (!writeready ()) return 0; + std::streamsize wlen = 0; + while(len > 0) { - int wval = -1; - do wval = ::write(fd(), buf, len); - while (wval == -1 && errno == EINTR); - if (wval == -1) + int wval = -1; + do + wval = ::write(fd(), buf, len); + while (wval == -1 && errno == EINTR); + if (wval == -1) { - if (errno != EAGAIN) perror("ipcbuf::write"); - return EOF; + if (errno != EAGAIN) perror("ipcbuf::write"); + return EOF; } - len -= wval; - wlen += wval; + len -= wval; + wlen += wval; } - return wlen; // == len if every thing is all right + return wlen; // == len if every thing is all right } std::streamsize ipcbuf::sys_read(char *buf, std::streamsize len) { - std::streamsize rval = -1; - do rval = ::read(fd(), buf, len); - while (rval == -1 && errno == EINTR); - if (rval == -1 && errno != EAGAIN) perror("ipcbuf::read"); - return rval; + std::streamsize rval = -1; + do + rval = ::read(fd(), buf, len); + while (rval == -1 && errno == EINTR); + if (rval == -1 && errno != EAGAIN) perror("ipcbuf::read"); + return rval; } Index: mmapbuf.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/mmapbuf.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- mmapbuf.cc 25 Mar 2001 08:25:16 -0000 1.4 +++ mmapbuf.cc 31 Oct 2003 22:33:12 -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 @@ -23,129 +23,107 @@ using namespace Prague; -mmapbuf::mmapbuf(int fd, int mode) - : mmap(fd, -1, MMap::read|MMap::write, MMap::shared), lock(fd) +mmapbuf::mmapbuf(int fd, int mode) : + mmap(fd, -1, MMap::read|MMap::write, MMap::shared), + lock(fd) { - if (mode == std::ios::in) + if (mode == std::ios::in) { - char_type *gbuf = reinterpret_cast<char_type *>(mmap.addr()); - setg(gbuf, gbuf, gbuf + mmap.size()); + char_type *gbuf = reinterpret_cast<char_type *>(mmap.addr()); + setg(gbuf, gbuf, gbuf + mmap.size()); } - else if (mode == std::ios::out) + else if (mode == std::ios::out) { - char_type *pbuf = reinterpret_cast<char_type *>(mmap.addr()); - setp(pbuf, pbuf + mmap.size()); + char_type *pbuf = reinterpret_cast<char_type *>(mmap.addr()); + setp(pbuf, pbuf + mmap.size()); } - else std::cerr << "mmapbuf::mmapbuf : invalid open mode" << std::endl; + else std::cerr << "mmapbuf::mmapbuf : invalid open mode" << std::endl; } -mmapbuf::mmapbuf(const std::string &file, size_t length, int mode) - : mmap(file, length, MMap::read|MMap::write, MMap::shared), lock(file, false) +mmapbuf::mmapbuf(const std::string &file, size_t length, int mode) : + mmap(file, length, MMap::read|MMap::write, MMap::shared), + lock(file, false) { - if (mode == std::ios::in) + if (mode == std::ios::in) { - char_type *gbuf = reinterpret_cast<char_type *>(mmap.addr()); - if (gbuf) setg(gbuf, gbuf, gbuf + mmap.size()); + char_type *gbuf = reinterpret_cast<char_type *>(mmap.addr()); + if (gbuf) setg(gbuf, gbuf, gbuf + mmap.size()); } - else if (mode == std::ios::out) + else if (mode == std::ios::out) { - char_type *pbuf = reinterpret_cast<char_type *>(mmap.addr()); - if (pbuf) setp(pbuf, pbuf + mmap.size()); + char_type *pbuf = reinterpret_cast<char_type *>(mmap.addr()); + if (pbuf) setp(pbuf, pbuf + mmap.size()); } - else std::cerr << "mmapbuf::mmapbuf : invalid open mode" << std::endl; + else std::cerr << "mmapbuf::mmapbuf : invalid open mode" << std::endl; } mmapbuf::~mmapbuf() { - overflow (EOF); // flush write buffer + overflow (EOF); // flush write buffer } -bool mmapbuf::readready() const -{ - return true; -} +bool mmapbuf::readready() const { return true; } -bool mmapbuf::writeready() const -{ - return true; -} +bool mmapbuf::writeready() const { return true; } -bool mmapbuf::exceptionpending() const -{ - return false; -} +bool mmapbuf::exceptionpending() const { return false; } -void mmapbuf::setnonblocking(bool flag) -{ -} +void mmapbuf::setnonblocking(bool flag) { } -bool mmapbuf::nonblocking() const -{ - return true; -} +bool mmapbuf::nonblocking() const { return true; } int mmapbuf::sync() { - mmap.sync(); - return 0; + mmap.sync(); + return 0; } int mmapbuf::showmanyc() const { - if (gptr() && gptr() < egptr()) return egptr() - gptr(); - return 0; + if (gptr() && gptr() < egptr()) return egptr() - gptr(); + return 0; } -mmapbuf::int_type mmapbuf::overflow(int c) -{ - return EOF; -} +mmapbuf::int_type mmapbuf::overflow(int c) { return EOF; } -mmapbuf::int_type mmapbuf::underflow() -{ - return EOF; -} +mmapbuf::int_type mmapbuf::underflow() { return EOF; } mmapbuf::int_type mmapbuf::uflow() { - int_type ret = underflow (); - if (ret == EOF) return EOF; - gbump(1); - return ret; + int_type ret = underflow (); + if (ret == EOF) return EOF; + gbump(1); + return ret; } -mmapbuf::int_type mmapbuf::pbackfail(int c) -{ - return EOF; -} +mmapbuf::int_type mmapbuf::pbackfail(int c) { return EOF; } std::streamsize mmapbuf::xsputn(const mmapbuf::char_type *s, std::streamsize n) { - int wval = epptr() - pptr(); - if (n <= wval) + int wval = epptr() - pptr(); + if (n <= wval) { - memcpy(pptr(), s, n * sizeof (char_type)); - pbump(n); - return n; + memcpy(pptr(), s, n * sizeof (char_type)); + pbump(n); + return n; } - memcpy (pptr(), s, wval * sizeof (char_type)); - pbump(wval); - if (overflow() != EOF) return wval + xsputn (s + wval, n - wval); - return wval; + memcpy (pptr(), s, wval * sizeof (char_type)); + pbump(wval); + if (overflow() != EOF) return wval + xsputn (s + wval, n - wval); + return wval; } std::streamsize mmapbuf::xsgetn(mmapbuf::char_type *s, std::streamsize n) { - int rval = showmanyc(); - if (rval >= n) + int rval = showmanyc(); + if (rval >= n) { - memcpy(s, gptr(), n * sizeof (char_type)); - gbump(n); - return n; + memcpy(s, gptr(), n * sizeof (char_type)); + gbump(n); + return n; } - memcpy(s, gptr(), rval * sizeof (char_type)); - gbump (rval); - if (underflow() != EOF) return rval + xsgetn(s + rval, n - rval); - return rval; - return 0; + memcpy(s, gptr(), rval * sizeof (char_type)); + gbump (rval); + if (underflow() != EOF) return rval + xsgetn(s + rval, n - rval); + return rval; } Index: pipebuf.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/pipebuf.cc,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- pipebuf.cc 25 Mar 2001 08:25:16 -0000 1.5 +++ pipebuf.cc 31 Oct 2003 22:33:12 -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 @@ -26,9 +26,9 @@ int pipebuf::open() { - int fds[2]; - if (pipe(fds) < 0) return -1; - if (fl & std::ios::out) {fd(fds[1]); return fds[0];} - else {fd(fds[0]); return fds[1];} -}; + int fds[2]; + if (pipe(fds) < 0) return -1; + if (fl & std::ios::out) {fd(fds[1]); return fds[0];} + else {fd(fds[0]); return fds[1];} +} Index: ptybuf.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/ptybuf.cc,v retrieving revision 1.18 retrieving revision 1.19 diff -u -d -r1.18 -r1.19 --- ptybuf.cc 29 Nov 2002 21:00:02 -0000 1.18 +++ ptybuf.cc 31 Oct 2003 22:33:12 -0000 1.19 @@ -1,10 +1,10 @@ /*$Id$ * - * This source file is a part of the Berlin Project. - * Copyright (C) 1999 Stefan Seefeld <[email protected]> + * This source file is a part of the Fresco Project. + * Copyright (C) 1999 Stefan Seefeld <[email protected]> * Copyright (C) 1995 Tatu Ylonen <[email protected]>, Espoo, Finland - * Copyright (C) 2001 Bastian Blank <[email protected]> - * http://www.berlin-consortium.org + * Copyright (C) 2001 Bastian Blank <[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 @@ -50,200 +50,188 @@ //inline char ctrl(char c) { return c & 0x1f;} -ptybuf::ptybuf() -: ipcbuf ( std::ios::in | std::ios::out ), tty ( -1 ) +ptybuf::ptybuf() : + ipcbuf(std::ios::in | std::ios::out), + tty(-1) { } ptybuf::~ptybuf() { - if ( tty != -1 ) - close ( tty ); + if (tty != -1) + close ( tty ); } std::streamsize ptybuf::sys_read(char *buf, std::streamsize len) { - std::streamsize rval = -1; - do rval = ::read(fd(), buf, len); - while (rval == -1 && errno == EINTR); - if (rval == -1 && errno == EIO) return 0; - if (rval == -1 && errno != EAGAIN) perror("ptybuf::read"); - return rval; + std::streamsize rval = -1; + do + rval = ::read(fd(), buf, len); + while (rval == -1 && errno == EINTR); + if (rval == -1 && errno == EIO) return 0; + if (rval == -1 && errno != EAGAIN) perror("ptybuf::read"); + return rval; } -int ptybuf::openpty () +int ptybuf::openpty() { - if ( tty == -1 ) - setup (); - return fd(); + if (tty == -1) + setup(); + return fd(); } -int ptybuf::opentty () +int ptybuf::opentty() { - if ( tty == -1 ) - setup (); - return tty; + if (tty == -1) + setup(); + return tty; } -void ptybuf::setup () +void ptybuf::setup() { - int ttyfd; - int ptyfd; + int ttyfd; + int ptyfd; #if defined(HAVE_OPENPTY) || defined(BSD4_4) - /* openpty(3) exists in OSF/1 and some other os'es */ - int i; - - i = ::openpty ( &ptyfd, &ttyfd, NULL, NULL, NULL ); - - if ( i < 0 ) - { - perror ( "openpty" ); - return; - } + /* openpty(3) exists in OSF/1 and some other os'es */ + if ()::openpty(&ptyfd, &ttyfd, NULL, NULL, NULL) < 0); + { + perror("openpty"); + return; + } - fd ( ptyfd ); - tty = ttyfd; - ptydev = ttyname ( ptyfd ); + fd(ptyfd); + tty = ttyfd; + ptydev = ttyname(ptyfd); #elif defined(HAVE__GETPTY) - /* - * _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates more - * pty's automagically when needed - */ - - char *name = _getpty ( &ptyfd, O_RDWR, 0622, 0 ); - if ( ! name ) - { - perror ( "_getpty" ); - return; - } + /* + * _getpty(3) exists in SGI Irix 4.x, 5.x & 6.x -- it generates more + * pty's automagically when needed + */ - /* Open the slave side. */ - ttyfd = open ( name, O_RDWR | O_NOCTTY ); + char *name = _getpty(&ptyfd, O_RDWR, 0622, 0); + if (!name) + { + perror("_getpty"); + return; + } - if ( ttyfd < 0 ) - { - perror ( name ); - close ( ptyfd ); - return; - } + // Open the slave side. + ttyfd = open(name, O_RDWR | O_NOCTTY); + if (ttyfd < 0) + { + perror(name); + close(ptyfd); + return; + } - fd ( ptyfd ); - tty = ttyfd; - ptydev = name; + fd(ptyfd); + tty = ttyfd; + ptydev = name; #elif defined(HAVE_DEV_PTMX) - /* - * This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3 - * also has bsd-style ptys, but they simply do not work.) - */ - int ptm; - mysig_t old_signal; - char *name; - - ptyfd = open ( "/dev/ptmx", O_RDWR | O_NOCTTY ); - - if ( ptyfd < 0 ) - { - perror ( "/dev/ptmx" ); - return; - } + /* + * This code is used e.g. on Solaris 2.x. (Note that Solaris 2.3 + * also has bsd-style ptys, but they simply do not work.) + */ + int ptm; + mysig_t old_signal; + char *name; - old_signal = mysignal ( SIGCHLD, SIG_DFL ); + ptyfd = open("/dev/ptmx", O_RDWR | O_NOCTTY); + if (ptyfd < 0) + { + perror("/dev/ptmx"); + return; + } - if ( grantpt ( ptyfd ) < 0 ) - { - perror ( "grantpt" ); - return; - } + old_signal = mysignal(SIGCHLD, SIG_DFL); - mysignal ( SIGCHLD, old_signal ); + if (grantpt(ptyfd) < 0) + { + perror("grantpt"); + return; + } - if ( unlockpt ( ptyfd ) < 0 ) - { - perror ( "unlockpt" ); - return; - } + mysignal(SIGCHLD, old_signal); - /* Open the slave side. */ - ttyfd = open ( name, O_RDWR | O_NOCTTY ); + if (unlockpt(ptyfd) < 0) + { + perror("unlockpt"); + return; + } - if ( ttyfd < 0 ) - { - perror ( name ); - close ( ptyfd ); - return; - } + // Open the slave side. + ttyfd = open(name, O_RDWR | O_NOCTTY); + if (ttyfd < 0) + { + perror(name); + close(ptyfd); + return; + } - fd ( ptyfd ); - tty = ttyfd; - ptydev = ptsname ( ptm ); + fd(ptyfd); + tty = ttyfd; + ptydev = ptsname(ptm); #elif defined(HAVE_DEV_PTS_AND_PTC) - /* AIX-style pty code. */ - - ptyfd = open ( "/dev/ptc", O_RDWR | O_NOCTTY ); - - if ( ptyfd < 0 ) - { - perror ( "Could not open /dev/ptc" ); - return; - } - - char *name = ttyname ( ptyfd ); + // AIX-style pty code. + ptyfd = open("/dev/ptc", O_RDWR | O_NOCTTY); + if (ptyfd < 0) + { + perror("Could not open /dev/ptc"); + return; + } - ttyfd = open ( name, O_RDWR | O_NOCTTY ); + char *name = ttyname(ptyfd); - if ( ttyfd < 0 ) - { - perror ( name ); - close ( ptyfd ); - return; - } + ttyfd = open(name, O_RDWR | O_NOCTTY); + if (ttyfd < 0) + { + perror(name); + close(ptyfd); + return; + } - fd ( ptyfd ); - tty = ttyfd; - ptydev = name; + fd(ptyfd); + tty = ttyfd; + ptydev = name; #else - /* BSD-style pty code. */ - char buf1[64]; - char buf2[64]; - int i; - const char *ptymajors = "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ"; - const char *ptyminors = "0123456789abcdef"; - int num_minors = strlen ( ptyminors ); - int num_ptys = strlen ( ptymajors ) * num_minors; - - for ( i = 0; i < num_ptys; i++ ) - { - snprintf ( buf1, sizeof buf1, "/dev/pty%c%c", ptymajors[i / num_minors], ptyminors[i % num_minors]); - snprintf ( buf2, sizeof buf2, "/dev/tty%c%c", ptymajors[i / num_minors], ptyminors[i % num_minors]); - - ptyfd = open ( buf1, O_RDWR | O_NOCTTY ); + // BSD-style pty code. + char buf1[64]; + char buf2[64]; + int i; + const char *ptymajors = "pqrstuvwxyzabcdefghijklmnoABCDEFGHIJKLMNOPQRSTUVWXYZ"; + const char *ptyminors = "0123456789abcdef"; + int num_minors = strlen ( ptyminors ); + int num_ptys = strlen ( ptymajors ) * num_minors; - if ( ptyfd < 0 ) + for ( i = 0; i < num_ptys; i++ ) { - /* Try SCO style naming */ - snprintf ( buf1, sizeof buf1, "/dev/ptyp%d", i ); - snprintf ( buf2, sizeof buf2, "/dev/ttyp%d", i ); + snprintf ( buf1, sizeof buf1, "/dev/pty%c%c", ptymajors[i / num_minors], ptyminors[i % num_minors]); + snprintf ( buf2, sizeof buf2, "/dev/tty%c%c", ptymajors[i / num_minors], ptyminors[i % num_minors]); - ptyfd = open ( buf1, O_RDWR | O_NOCTTY ); + ptyfd = open ( buf1, O_RDWR | O_NOCTTY ); - if ( ptyfd < 0 ) - continue; - } + if ( ptyfd < 0 ) + { + /* Try SCO style naming */ + snprintf ( buf1, sizeof buf1, "/dev/ptyp%d", i ); + snprintf ( buf2, sizeof buf2, "/dev/ttyp%d", i ); - /* Open the slave side. */ - ttyfd = open ( buf2, O_RDWR | O_NOCTTY ); + ptyfd = open ( buf1, O_RDWR | O_NOCTTY ); + if ( ptyfd < 0 ) continue; + } - if ( ttyfd < 0 ) - { - perror ( buf2 ); - close ( ptyfd ); - return; - } + /* Open the slave side. */ + ttyfd = open ( buf2, O_RDWR | O_NOCTTY ); + if ( ttyfd < 0 ) + { + perror ( buf2 ); + close ( ptyfd ); + return; + } - fd ( ptyfd ); - tty = ttyfd; - ptydev = buf1; - } + fd(ptyfd); + tty = ttyfd; + ptydev = buf1; + } #endif } - Index: sockbuf.cc =================================================================== RCS file: /cvs/fresco/Fresco/Prague/src/IPC/sockbuf.cc,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- sockbuf.cc 28 Mar 2001 06:09:47 -0000 1.11 +++ sockbuf.cc 31 Oct 2003 22:33:12 -0000 1.12 @@ -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 @@ -41,496 +41,498 @@ using namespace Prague; -const char *sockerr::errstr () const +const char *sockerr::errstr() const { - return strerror(err); + return strerror(err); } bool sockerr::io() const // recoverable io error. { - switch (err) + switch (err) { - case EWOULDBLOCK: - case EINPROGRESS: - case EALREADY: - return true; + case EWOULDBLOCK: + case EINPROGRESS: + case EALREADY: + return true; } - return false; + return false; } bool sockerr::arg() const // recoverable argument error. { - switch (err) + switch (err) { - case ENOTSOCK: - case EDESTADDRREQ: - case EMSGSIZE: - case EPROTOTYPE: - case ENOPROTOOPT: - case EPROTONOSUPPORT: - case ESOCKTNOSUPPORT: - case EOPNOTSUPP: - case EPFNOSUPPORT: - case EAFNOSUPPORT: - case EADDRINUSE: - case EADDRNOTAVAIL: - return true; + case ENOTSOCK: + case EDESTADDRREQ: + case EMSGSIZE: + case EPROTOTYPE: + case ENOPROTOOPT: + case EPROTONOSUPPORT: + case ESOCKTNOSUPPORT: + case EOPNOTSUPP: + case EPFNOSUPPORT: + case EAFNOSUPPORT: + case EADDRINUSE: + case EADDRNOTAVAIL: + return true; } - return false; + return false; } bool sockerr::op() const -// operational error encountered +// operational error encountered { - switch (err) + switch (err) { - case ENETDOWN: - case ENETUNREACH: - case ENETRESET: - case ECONNABORTED: - case ECONNRESET: - case ENOBUFS: - case EISCONN: - case ENOTCONN: - case ESHUTDOWN: - case ETOOMANYREFS: - case ETIMEDOUT: - case ECONNREFUSED: - case ELOOP: - case ENAMETOOLONG: - case EHOSTDOWN: - case EHOSTUNREACH: - case ENOTEMPTY: - // case EPROCLIM: - case EUSERS: - case EDQUOT: - return true; + case ENETDOWN: + case ENETUNREACH: + case ENETRESET: + case ECONNABORTED: + case ECONNRESET: + case ENOBUFS: + case EISCONN: + case ENOTCONN: + case ESHUTDOWN: + case ETOOMANYREFS: + case ETIMEDOUT: + case ECONNREFUSED: + case ELOOP: + case ENAMETOOLONG: + case EHOSTDOWN: + case EHOSTUNREACH: + case ENOTEMPTY: + // case EPROCLIM: + case EUSERS: + case EDQUOT: + return true; } - return false; + return false; } bool sockerr::conn() const // return true if err is EISCONN, ENOTCONN, ECONNRESET, ECONNREFUSED, // ETIMEDOUT, or EPIPE { - switch (err) + switch (err) { - case EISCONN: - case ENOTCONN: - case ECONNRESET: - case ECONNREFUSED: - case ETIMEDOUT: - case EPIPE: - return true; + case EISCONN: + case ENOTCONN: + case ECONNRESET: + case ECONNREFUSED: + case ETIMEDOUT: + case EPIPE: + return true; } - return false; + return false; } bool sockerr::addr() const // return true if err is EADDRINUSE or EADDRNOTAVAIL { - switch (err) + switch (err) { - case EADDRINUSE: - case EADDRNOTAVAIL: - return true; + case EADDRINUSE: + case EADDRNOTAVAIL: + return true; } - return false; + return false; } bool sockerr::benign() const // return true if err is EINTR, EWOULDBLOCK, or EAGAIN { - switch (err) + switch (err) { - case EINTR: - case EWOULDBLOCK: - // case EAGAIN: - return true; + case EINTR: + case EWOULDBLOCK: + // case EAGAIN: + return true; } - return false; + return false; } sockunixaddr::sockunixaddr(const std::string &path) { - sun_family = sockunixbuf::af_unix; - ::strcpy(sun_path, path.c_str()); + sun_family = sockunixbuf::af_unix; + ::strcpy(sun_path, path.c_str()); } sockunixaddr::sockunixaddr(const sockunixaddr &suna) { - sun_family = sockunixbuf::af_unix; - ::strcpy (sun_path, suna.sun_path); + sun_family = sockunixbuf::af_unix; + ::strcpy (sun_path, suna.sun_path); } -sockinetaddr::sockinetaddr() +sockinetaddr::sockinetaddr() { - sin_family = sockinetbuf::af_inet4; - sin_addr.s_addr = htonl(INADDR_ANY); - sin_port = 0; + sin_family = sockinetbuf::af_inet4; + sin_addr.s_addr = htonl(INADDR_ANY); + sin_port = 0; } sockinetaddr::sockinetaddr(unsigned long addr, int port_no) // addr and port_no are in host byte order { - sin_family = sockbuf::af_inet4; - sin_addr.s_addr = htonl(addr); - sin_port = htons(port_no); + sin_family = sockbuf::af_inet4; + sin_addr.s_addr = htonl(addr); + sin_port = htons(port_no); } sockinetaddr::sockinetaddr(unsigned long addr, const std::string &sn, const std::string &pn) // addr is in host byte order { - sin_family = sockbuf::af_inet4; - sin_addr.s_addr = htonl(addr); - port(sn, pn); + sin_family = sockbuf::af_inet4; + sin_addr.s_addr = htonl(addr); + port(sn, pn); } sockinetaddr::sockinetaddr(const std::string &host_name, int port_no) // port_no is in host byte order { - addr(host_name); - sin_port = htons(port_no); + addr(host_name); + sin_port = htons(port_no); } sockinetaddr::sockinetaddr(const std::string &hn, const std::string &sn, const std::string &pn) { - addr(hn); - port(sn, pn); + addr(hn); + port(sn, pn); } sockinetaddr::sockinetaddr(const sockinetaddr &sina) { - sin_family = sockbuf::af_inet4; - sin_addr.s_addr = sina.sin_addr.s_addr; - sin_port = sina.sin_port; -} + sin_family = sockbuf::af_inet4; + sin_addr.s_addr = sina.sin_addr.s_addr; + sin_port = sina.sin_port; +} void sockinetaddr::port(const std::string &sn, const std::string &pn) { - servent *sp = getservbyname(sn.c_str(), pn.c_str()); - if (sp == 0) throw sockerr (EADDRNOTAVAIL); - sin_port = sp->s_port; + servent *sp = getservbyname(sn.c_str(), pn.c_str()); + if (sp == 0) throw sockerr (EADDRNOTAVAIL); + sin_port = sp->s_port; } int sockinetaddr::port() const { - return ntohs(sin_port); + return ntohs(sin_port); } void sockinetaddr::addr(const std::string &host) { - in_addr ia; - if (inet_aton(host.c_str(), &ia) == 0) + in_addr ia; + if (inet_aton(host.c_str(), &ia) == 0) { - hostent *hp = gethostbyname(host.c_str()); - if (!hp) - { - std::cerr << "sockinetaddr::addr :" << std::endl; - std::cerr << "error in host lookup" << std::endl; - std::cerr << "error processing for this problem has not yet been implemented, sorry" << std::endl; - exit(-1); - } - memcpy(&sin_addr, hp->h_addr, hp->h_length); - sin_family = hp->h_addrtype; + hostent *hp = gethostbyname(host.c_str()); + if (!hp) + { + std::cerr << "sockinetaddr::addr :" << std::endl + << "error in host lookup" << std::endl + << "error processing for this problem has not " + << "yet been implemented, sorry" << std::endl; + exit(-1); + } + memcpy(&sin_addr, hp->h_addr, hp->h_length); + sin_family = hp->h_addrtype; } - else + else { - sin_addr.s_addr = inet_lnaof(ia); - sin_family = sockbuf::af_inet4; + sin_addr.s_addr = inet_lnaof(ia); + sin_family = sockbuf::af_inet4; } } std::string sockinetaddr::hostname() const { - if (sin_addr.s_addr == htonl(INADDR_ANY)) + if (sin_addr.s_addr == htonl(INADDR_ANY)) { - char name[64]; - if (gethostname(name, 63) == -1) return ""; - return name; + char name[64]; + if (gethostname(name, 63) == -1) return ""; + return name; } - hostent *hp = gethostbyaddr((const char *) &sin_addr, sizeof(sin_addr), family()); - if (hp == 0) return ""; - if (hp->h_name) return hp->h_name; - return ""; + hostent *hp = gethostbyaddr((const char *) &sin_addr, sizeof(sin_addr), family()); + if (hp == 0) return ""; + if (hp->h_name) return hp->h_name; + return ""; } -sockbuf::sockbuf(int domain, sockbuf::type st, int proto) - : ipcbuf(std::ios::in|std::ios::out) +sockbuf::sockbuf(int domain, sockbuf::type st, int proto) : + ipcbuf(std::ios::in|std::ios::out) { - int socket = ::socket(domain, st, proto); - if (socket == -1) throw sockerr (errno); - else fd(socket); + int socket = ::socket(domain, st, proto); + if (socket == -1) throw sockerr (errno); + else fd(socket); } int sockbuf::getopt(int op, void *buf, socklen_t len, int level) const { - if (::getsockopt(fd(), level, op, (char *)buf, &len) == -1) throw sockerr(errno); - return len; + if (::getsockopt(fd(), level, op, (char *)buf, &len) == -1) throw sockerr(errno); + return len; } void sockbuf::setopt(int op, void *buf, socklen_t len, int level) const { - if (::setsockopt(fd(), level, op, (char *) buf, len) == -1) throw sockerr(errno); + if (::setsockopt(fd(), level, op, (char *) buf, len) == -1) throw sockerr(errno); } void sockbuf::listen(int num) { - if (::listen(fd(), num) == -1) throw sockerr(errno); + if (::listen(fd(), num) == -1) throw sockerr(errno); } sockbuf::socklinger sockbuf::linger() const { - socklinger old(0, 0); - getopt(so_linger, &old, sizeof(old)); - return old; + socklinger old(0, 0); + getopt(so_linger, &old, sizeof(old)); + return old; } sockbuf::socklinger sockbuf::linger(sockbuf::socklinger opt) const { - socklinger old(0, 0); - getopt(so_linger, &old, sizeof(old)); - setopt(so_linger, &opt, sizeof(opt)); - return old; + socklinger old(0, 0); + getopt(so_linger, &old, sizeof(old)); + setopt(so_linger, &opt, sizeof(opt)); + return old; } bool sockbuf::atmark() const { - int arg; - if (::ioctl(fd(), SIOCATMARK, &arg) == -1) throw sockerr(errno); - return arg; + int arg; + if (::ioctl(fd(), SIOCATMARK, &arg) == -1) throw sockerr(errno); + return arg; } int sockbuf::pgrp() const { - int arg; - if (::ioctl(fd(), SIOCGPGRP, &arg) == -1) throw sockerr(errno); - return arg; + int arg; + if (::ioctl(fd(), SIOCGPGRP, &arg) == -1) throw sockerr(errno); + return arg; } int sockbuf::pgrp(int new_pgrp) const { - int old = pgrp(); - if (::ioctl(fd(), SIOCSPGRP, &new_pgrp) == -1) throw sockerr(errno); - return old; + int old = pgrp(); + if (::ioctl(fd(), SIOCSPGRP, &new_pgrp) == -1) throw sockerr(errno); + return old; } sockbuf::type sockbuf::gettype() const { - int ty=0; - getopt(so_type, &ty, sizeof (ty)); - return sockbuf::type(ty); + int ty=0; + getopt(so_type, &ty, sizeof (ty)); + return sockbuf::type(ty); } int sockbuf::clearerror() const { - int err=0; - getopt (so_error, &err, sizeof (err)); - return err; + int err=0; + getopt (so_error, &err, sizeof (err)); + return err; } bool sockbuf::debug() const { - int old = 0; - getopt (so_debug, &old, sizeof (old)); - return old; + int old = 0; + getopt (so_debug, &old, sizeof (old)); + return old; } bool sockbuf::debug(bool set) const { - int old=0; - int opt = set; - getopt(so_debug, &old, sizeof (old)); - try + int old=0; + int opt = set; + getopt(so_debug, &old, sizeof (old)); + try { setopt (so_debug, &opt, sizeof (opt)); } - catch (sockerr e) { std::cerr << errno << ' ' << e.errstr() << std::endl;} - return old; + catch (sockerr e) + { std::cerr << errno << ' ' << e.errstr() << std::endl;} + return old; } bool sockbuf::reuseaddr() const { - int old = 0; - getopt(so_reuseaddr, &old, sizeof (old)); - return old; + int old = 0; + getopt(so_reuseaddr, &old, sizeof (old)); + return old; } bool sockbuf::reuseaddr(bool set) const { - int old=0; - int opt = set; - getopt (so_reuseaddr, &old, sizeof (old)); - setopt (so_reuseaddr, &opt, sizeof (opt)); - return old; + int old=0; + int opt = set; + getopt (so_reuseaddr, &old, sizeof (old)); + setopt (so_reuseaddr, &opt, sizeof (opt)); + return old; } bool sockbuf::keepalive() const { - int old = 0; - getopt (so_keepalive, &old, sizeof (old)); - return old; + int old = 0; + getopt (so_keepalive, &old, sizeof (old)); + return old; } bool sockbuf::keepalive(bool set) const { - int old=0; - int opt = set; - getopt (so_keepalive, &old, sizeof (old)); - setopt (so_keepalive, &opt, sizeof (opt)); - return old; + int old=0; + int opt = set; + getopt (so_keepalive, &old, sizeof (old)); + setopt (so_keepalive, &opt, sizeof (opt)); + return old; } int sockbuf::read(void *buf, int len) { -// if (data->rtmo != -1 && !readready()) -// throw sockerr(ETIMEDOUT); - - if (oob() && atmark()) - throw sockoob(); + // if (data->rtmo != -1 && !readready()) + // throw sockerr(ETIMEDOUT); - int rval = 0; - if ((rval = ::read (fd(), (char *)buf, len)) == -1) - throw sockerr(errno); - return rval; + if (oob() && atmark()) + throw sockoob(); + + int rval = 0; + if ((rval = ::read (fd(), (char *)buf, len)) == -1) + throw sockerr(errno); + return rval; } int sockbuf::recv(void *buf, int len, int msgf) { -// if (data->rtmo != -1 && !readready()) -// throw sockerr(ETIMEDOUT); - - if (oob() && atmark()) - throw sockoob(); + // if (data->rtmo != -1 && !readready()) + // throw sockerr(ETIMEDOUT); - int rval = 0; - if ((rval = ::recv(fd(), (char*) buf, len, msgf)) == -1) - throw sockerr (errno); - return rval; + if (oob() && atmark()) + throw sockoob(); + + int rval = 0; + if ((rval = ::recv(fd(), (char*) buf, len, msgf)) == -1) + throw sockerr (errno); + return rval; } int sockbuf::recvfrom(sockaddr &sa, void *buf, int len, int msgf) { -// if (data->rtmo != -1 && !readready()) -// throw sockerr(ETIMEDOUT); - - if (oob() && atmark()) - throw sockoob(); + // if (data->rtmo != -1 && !readready()) + // throw sockerr(ETIMEDOUT); - int rval = 0; - socklen_t sa_length = sa.size (); - - if ((rval = ::recvfrom(fd(), (char*) buf, len, msgf, sa.addr(), &sa_length)) == -1) - throw sockerr (errno); - return rval; + if (oob() && atmark()) + throw sockoob(); + + int rval = 0; + socklen_t sa_length = sa.size (); + + if ((rval = ::recvfrom(fd(), (char*) buf, len, msgf, sa.addr(), &sa_length)) == -1) + throw sockerr (errno); + return rval; } int sockbuf::write(const void *buf, int len) // upon error, write throws the number of bytes writen so far instead // of sockerr. { -// if (data->stmo != -1 && !writeready()) -// throw sockerr(ETIMEDOUT); - int wlen = 0; - while(len > 0) + // if (data->stmo != -1 && !writeready()) + // throw sockerr(ETIMEDOUT); + int wlen = 0; + while(len > 0) { - int wval = ::write(fd(), (char*) buf, len); - if (wval == -1) throw wlen; - len -= wval; - wlen += wval; + int wval = ::write(fd(), (char*) buf, len); + if (wval == -1) throw wlen; + len -= wval; + wlen += wval; } - return wlen; // == len if every thing is all right + return wlen; // == len if every thing is all right } int sockbuf::send(const void *buf, int len, int msgf) // upon error, write throws the number of bytes writen so far instead // of sockerr. { -// if (fd() != -1 && !writeready()) -// throw sockerr (ETIMEDOUT); - - int wlen = 0; - while(len > 0) + // if (fd() != -1 && !writeready()) + // throw sockerr (ETIMEDOUT); + + int wlen = 0; + while(len > 0) { - int wval = ::send (fd(), (char*) buf, len, msgf); - if (wval == -1) throw wlen; - len -= wval; - wlen += wval; + int wval = ::send (fd(), (char*) buf, len, msgf); + if (wval == -1) throw wlen; + len -= wval; + wlen += wval; } - return wlen; + return wlen; } int sockbuf::sendto(sockaddr &sa, const void *buf, int len, int msgf) // upon error, write throws the number of bytes writen so far instead // of sockerr. { -// if (fd() != -1 && !writeready()) -// throw sockerr (ETIMEDOUT); - int wlen = 0; - while(len > 0) + // if (fd() != -1 && !writeready()) + // throw sockerr (ETIMEDOUT); + int wlen = 0; + while(len > 0) { - int wval = ::sendto(fd(), (char *)buf, len, msgf, sa.addr (), sa.size()); - if (wval == -1) throw wlen; - len -= wval; - wlen += wval; + int wval = ::sendto(fd(), (char *)buf, len, msgf, sa.addr (), sa.size()); + if (wval == -1) throw wlen; + len -= wval; + wlen += wval; } - return wlen; + return wlen; } sockunixaddr sockunixbuf::addr() const { - sockunixaddr sa; - socklen_t len = sa.size(); - if (::getsockname(fd(), sa.addr(), &len) == -1) throw sockerr (errno); - return sa; + sockunixaddr sa; + socklen_t len = sa.size(); + if (::getsockname(fd(), sa.addr(), &len) == -1) throw sockerr (errno); + return sa; } void sockunixbuf::bind(const sockunixaddr &sa) { - if (::bind (fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); + if (::bind (fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); } sockunixbuf *sockunixbuf::accept(sockunixaddr &sa) { - socklen_t len = sa.size(); - int soc = -1; - if ((soc = ::accept(fd(), sa.addr(), &len)) == -1) throw sockerr(errno); - return new sockunixbuf(soc); + socklen_t len = sa.size(); + int soc = -1; + if ((soc = ::accept(fd(), sa.addr(), &len)) == -1) throw sockerr(errno); + return new sockunixbuf(soc); } sockunixbuf *sockunixbuf::accept() { - int soc = -1; - if ((soc = ::accept(fd(), 0, 0)) == -1) throw sockerr(errno); - return new sockunixbuf(soc); + int soc = -1; + if ((soc = ::accept(fd(), 0, 0)) == -1) throw sockerr(errno); + return new sockunixbuf(soc); } void sockunixbuf::connect(const sockunixaddr &sa) { - if (::connect(fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); + if (::connect(fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); } sockinetaddr sockinetbuf::localaddr() const { - sockinetaddr sa; - socklen_t len = sa.size(); - if (::getsockname(fd(), sa.addr(), &len) == -1) throw sockerr(errno); - return sa; + sockinetaddr sa; + socklen_t len = sa.size(); + if (::getsockname(fd(), sa.addr(), &len) == -1) throw sockerr(errno); + return sa; } sockinetaddr sockinetbuf::peeraddr() const { - sockinetaddr sa; - socklen_t len = sa.size(); - if (::getpeername(fd(), sa.addr(), &len) == -1) throw sockerr(errno); - return sa; + sockinetaddr sa; + socklen_t len = sa.size(); + if (::getpeername(fd(), sa.addr(), &len) == -1) throw sockerr(errno); + return sa; } void sockinetbuf::bind(const sockinetaddr &sa) { - if (::bind (fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); + if (::bind (fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); } void sockinetbuf::bind_until_success(int portno) @@ -538,57 +540,57 @@ // b. if success return // c. if failure and errno is EADDRINUSE, portno++ and go to step a. { - for (;;) + for (;;) { - try - { - bind(sockinetaddr((unsigned long) INADDR_ANY, portno++)); - } - catch (const sockerr &e) - { - if (e.number() != EADDRINUSE) throw; - continue; - } - break; + try + { + bind(sockinetaddr((unsigned long) INADDR_ANY, portno++)); + } + catch (const sockerr &e) + { + if (e.number() != EADDRINUSE) throw; + continue; + } + break; } } void sockinetbuf::connect(const sockinetaddr &sa) { - if (::connect(fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); + if (::connect(fd(), sa.addr(), sa.size()) == -1) throw sockerr(errno); } sockinetbuf *sockinetbuf::accept(sockinetaddr &sa) { - socklen_t len = sa.size(); - int soc = -1; - if ((soc = ::accept(fd(), sa.addr(), &len)) == -1) throw sockerr(errno); - return new sockinetbuf(soc); + socklen_t len = sa.size(); + int soc = -1; + if ((soc = ::accept(fd(), sa.addr(), &len)) == -1) throw sockerr(errno); + return new sockinetbuf(soc); } sockinetbuf *sockinetbuf::accept() { - int soc = -1; - if ((soc = ::accept(fd(), 0, 0)) == -1) throw sockerr(errno); - return new sockinetbuf(soc); + int soc = -1; + if ((soc = ::accept(fd(), 0, 0)) == -1) throw sockerr(errno); + return new sockinetbuf(soc); } bool sockinetbuf::tcpnodelay() const { - struct protoent *proto = getprotobyname("tcp"); - if (proto == 0) throw sockerr(ENOPROTOOPT); - int old = 0; - getopt(TCP_NODELAY, &old, sizeof(old), proto->p_proto); - return old; + struct protoent *proto = getprotobyname("tcp"); + if (proto == 0) throw sockerr(ENOPROTOOPT); + int old = 0; + getopt(TCP_NODELAY, &old, sizeof(old), proto->p_proto); + return old; } bool sockinetbuf::tcpnodelay(bool set) const { - struct protoent *proto = getprotobyname("tcp"); - if (proto == 0) throw sockerr(ENOPROTOOPT); - int old = 0; - int opt = set; - getopt(TCP_NODELAY, &old, sizeof(old), proto->p_proto); - setopt(TCP_NODELAY, &opt, sizeof(opt), proto->p_proto); - return old; + struct protoent *proto = getprotobyname("tcp"); + if (proto == 0) throw sockerr(ENOPROTOOPT); + int old = 0; + int opt = set; + getopt(TCP_NODELAY, &old, sizeof(old), proto->p_proto); + setopt(TCP_NODELAY, &opt, sizeof(opt), proto->p_proto); + return old; }