if(othreaded){
c->start();
}
else {
opoll.append(fd);
}
}
else if(fd == oclientGoneEvent.getFd()){
oclientGoneEvent.getEvent(fd);
dprintf("Client Gone Event: Fd: %d\n", fd);
if(othreaded){
for(oclients.start(i); !oclients.isEnd(i); oclients.next(i)){
if(oclients[i]->getSocket().getFd() == fd){
oclients[i]->waitForCompletion();
delete oclients[i];
oclients.del(i);
break;
}
}
}
}
else if(fd == onetEvent.getFd()){
processEvent(fd);
}
else if(fd >= 0){
dprintf("Process Client: %d\n", fd);
for(oclients.start(i); !oclients.isEnd(i); oclients.next(i)){
if(oclients[i]->getSocket().getFd() == fd){
if(e = oclients[i]->process()){
dprintf("ClientGone: %d Error: %s\n", fd, e.getString().retStr());
opoll.delFd(fd);
delete oclients[i];
oclients.del(i);
}
break;
}
}
}
}
return err;
}
BError BoapServer::addObject(BoapServiceObject* object){
BError err;
oservices.append(BoapServiceEntry(oservices.number(), object));
return err;
}
BError BoapServer::process(BoapServerConnection* conn, BoapPacket& rx, BoapPacket& tx){
BError err;
BIter i;
BoapPacketHead head;
rx.popHead(head);
for(oservices.start(i); !oservices.isEnd(i); oservices.next(i)){
if(oservices[i].oservice == head.service){
err = oservices[i].oobject->process(conn, rx, tx);
break;
}
}
return err;
}
BError BoapServer::processEvent(BoapPacket& rx){
BError err;
BIter i;
int s;
dprintf("BoapServer::processEvent\n");
for(oservices.start(i), s = 0; !oservices.isEnd(i); oservices.next(i), s++){
err = oservices[i].oobject->processEvent(rx);
}
return err;
}
BError BoapServer::processEvent(int fd){
BError err;
int nb = 0;
BoapPacketHead head;
BoapPacket rx;
// Recieve Packet
rx.resize(1500);
if((nb = recv(fd, rx.data(), 1500, 0)) < 0)
return BError(errno, strerror(errno));
rx.popHead(head);
dprintf("Event received: Len(%d) Service(%d) Cmd(%d)\n", head.length, head.service, head.cmd);
return processEvent(rx);
}
BError BoapServer::sendEvent(BoapPacket& tx){
BError err;
int nb = 0;
char* data = 0;
int n = 0;