void Network::accept_stream(void) { NetStream *s = wait_for_connect(); cerr << "Network accept_stream from ---->" << s->name() << endl; add_stream(s); add_client(s); // notify observers notify_net(Network_obs::accept_str, s); }
int NetStream::interpret() { char buff_[256], *buff = buff_; NETenum code; int port; processing_ = 1; int ret = 0; while (_in_queue.count()) { *this >> code; switch (code) { case NETadd_connection: { *this >> buff >> port; NetStream *s = new NetStream(port, buff); if (s->fd() != -1) network_->add_stream(s); network_->interpret(code, this); } brcase NETquit: { network_->interpret(code, this); network_->remove_stream(this); ret = 1; // this return value should terminate this NetStream } brcase NETidentify : *this >> port; set_port(port); if (network_->first_) { cerr << "NetStream accepts server -->" << print_name()<<endl; for (int i=0; i<network_->nStreams_; i++) { NetStream *s = network_->streams_[i]; if (s->port() != -1 && s != this) { *this << NETadd_connection << s->name() << s->port() << NETflush; } } } brcase NETtext: *this >> buff; cerr << "(* " << print_name() << " *) " << buff << endl; brcase NETbroadcast: { str_ptr flag; *this >> flag; int i; for (i = 0; i < tags_.num(); i++) if (flag == tags_[i]) break; if (i == tags_.num()) { _in_queue.remove_all(); if (Config::get_var_bool("PRINT_ERRS",false,true)) cerr << "Ignoring broadcast " << flag << endl; } } brcase NETbarrier: network_->_at_barrier++; brdefault : //XXX - Added a way to bail out of bad stream... if (network_->interpret(code, this)) return 1; } } processing_ = 0; return ret; }