Loading src/event/kqueue.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ namespace netplus { NetException except; struct kevent setevent = { 0 }; EV_SET(&setevent,curcon->csock->fd(),events,EV_ADD | EV_DISPATCH| EV_ONESHOT,0,0,curcon); EV_SET(&setevent,curcon->csock->fd(),events,EV_ADD | EV_ONESHOT,0,0,curcon); if ( kevent(_pollFD, &setevent, 1, nullptr, 0, nullptr) < 0) { except[NetException::Error] << "_setPollEvents: can change socket!"; Loading Loading @@ -163,6 +163,7 @@ namespace netplus { } _evtapi->CreateConnetion(&ccon); if(_ServerSocket->_Type==sockettype::TCP){ ccon->csock=new tcp(); }else if(_ServerSocket->_Type==sockettype::UDP){ Loading @@ -174,7 +175,6 @@ namespace netplus { _ServerSocket->accept(ccon->csock); ccon->csock->setnonblocking(); std::string ip; ccon->csock->getAddress(ip); std::cout << "Connected: " << ip << std::endl; Loading @@ -184,7 +184,7 @@ namespace netplus { struct kevent setevent { 0 }; EV_SET(&setevent, ccon->csock->fd(), EVFILT_READ, EV_ADD | EV_DISPATCH | EV_ONESHOT,0,0,ccon); EV_SET(&setevent, ccon->csock->fd(), EVFILT_READ, EV_ADD | EV_ONESHOT,0,0,ccon); int estate = kevent(_pollFD, &setevent, 1, nullptr, 0, nullptr); Loading Loading @@ -218,11 +218,11 @@ namespace netplus { if(!rcon->SendData.empty()){ rcon->state=EVOUT; setpollEvents(rcon,EVFILT_WRITE | EV_DISPATCH | EV_ONESHOT); setpollEvents(rcon,EVFILT_WRITE | EV_ONESHOT); return; } setpollEvents(rcon,EVFILT_READ | EV_DISPATCH | EV_ONESHOT); setpollEvents(rcon,EVFILT_READ | EV_ONESHOT); }catch(NetException &e){ if(e.getErrorType()== NetException::Note){ Loading Loading @@ -262,7 +262,7 @@ namespace netplus { }catch(NetException &e){ if(e.getErrorType()== NetException::Note){ wcon->state=EVOUT; setpollEvents(wcon,EVFILT_WRITE | EV_DISPATCH | EV_ONESHOT); setpollEvents(wcon,EVFILT_WRITE | EV_ONESHOT); return; }else{ throw e; Loading src/posix/socket.cpp +18 −18 Original line number Diff line number Diff line Loading @@ -149,16 +149,16 @@ netplus::tcp::~tcp(){ } netplus::tcp::tcp() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); _SocketPtr=::malloc(sizeof(struct sockaddr)); _SocketPtrSize=sizeof(struct sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _Socket=::socket(((struct sockaddr*)_SocketPtr)->sa_family,SOCK_STREAM,0);; _Type=sockettype::TCP; } netplus::tcp::tcp(int sock) { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); _SocketPtr=::malloc(sizeof(struct sockaddr)); _SocketPtrSize=sizeof(struct sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _Socket=sock; _Type=sockettype::TCP; Loading Loading @@ -189,9 +189,10 @@ int netplus::tcp::getMaxconnections(){ void netplus::tcp::accept(socket *csock){ NetException exception; struct sockaddr myaddr; socklen_t myaddrlen=sizeof(myaddr); *csock=::accept(_Socket,(struct sockaddr *)&myaddr,&myaddrlen); *csock=::accept(_Socket,(struct sockaddr *)csock->_SocketPtr, &csock->_SocketPtrSize); if(csock->_Socket<0){ int etype=NetException::Error; if(errno==EAGAIN) Loading @@ -202,9 +203,6 @@ void netplus::tcp::accept(socket *csock){ exception[etype] << "Can't accept on Socket: " << errstr; throw exception; } csock->_SocketPtrSize = myaddrlen; csock->_SocketPtr = malloc(myaddrlen); memcpy(csock->_SocketPtr,&myaddr,myaddrlen); } void netplus::tcp::bind(){ Loading @@ -219,17 +217,19 @@ void netplus::tcp::bind(){ unsigned int netplus::tcp::sendData(socket *csock, void* data, unsigned long size){ return sendData(csock,data,size,0); } #include <iostream> unsigned int netplus::tcp::sendData(socket *csock, void* data, unsigned long size,int flags){ NetException exception; int rval=::sendto(csock->_Socket, std::cout << (unsigned int)csock->_SocketPtrSize <<std::endl; int rval=::sendto(csock->fd(), data, size, flags, (struct sockaddr *)&csock->_SocketPtr, csock->_SocketPtrSize (struct sockaddr *)csock->_SocketPtr, sizeof(struct sockaddr) ); if(rval<0){ int etype=NetException::Error; Loading @@ -254,11 +254,11 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz NetException exception; int recvsize=::recvfrom(csock->_Socket, int recvsize=::recvfrom(csock->fd(), data, size, flags, (struct sockaddr *)&csock->_SocketPtr, (struct sockaddr *)csock->_SocketPtr, &csock->_SocketPtrSize ); if(recvsize<0){ Loading @@ -277,6 +277,7 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz } return recvsize; } void netplus::tcp::connect(socket *csock){ NetException exception; Loading @@ -290,7 +291,6 @@ void netplus::tcp::connect(socket *csock){ } } void netplus::tcp::getAddress(std::string &addr){ if(!_SocketPtr) return; Loading Loading
src/event/kqueue.cpp +6 −6 Original line number Diff line number Diff line Loading @@ -123,7 +123,7 @@ namespace netplus { NetException except; struct kevent setevent = { 0 }; EV_SET(&setevent,curcon->csock->fd(),events,EV_ADD | EV_DISPATCH| EV_ONESHOT,0,0,curcon); EV_SET(&setevent,curcon->csock->fd(),events,EV_ADD | EV_ONESHOT,0,0,curcon); if ( kevent(_pollFD, &setevent, 1, nullptr, 0, nullptr) < 0) { except[NetException::Error] << "_setPollEvents: can change socket!"; Loading Loading @@ -163,6 +163,7 @@ namespace netplus { } _evtapi->CreateConnetion(&ccon); if(_ServerSocket->_Type==sockettype::TCP){ ccon->csock=new tcp(); }else if(_ServerSocket->_Type==sockettype::UDP){ Loading @@ -174,7 +175,6 @@ namespace netplus { _ServerSocket->accept(ccon->csock); ccon->csock->setnonblocking(); std::string ip; ccon->csock->getAddress(ip); std::cout << "Connected: " << ip << std::endl; Loading @@ -184,7 +184,7 @@ namespace netplus { struct kevent setevent { 0 }; EV_SET(&setevent, ccon->csock->fd(), EVFILT_READ, EV_ADD | EV_DISPATCH | EV_ONESHOT,0,0,ccon); EV_SET(&setevent, ccon->csock->fd(), EVFILT_READ, EV_ADD | EV_ONESHOT,0,0,ccon); int estate = kevent(_pollFD, &setevent, 1, nullptr, 0, nullptr); Loading Loading @@ -218,11 +218,11 @@ namespace netplus { if(!rcon->SendData.empty()){ rcon->state=EVOUT; setpollEvents(rcon,EVFILT_WRITE | EV_DISPATCH | EV_ONESHOT); setpollEvents(rcon,EVFILT_WRITE | EV_ONESHOT); return; } setpollEvents(rcon,EVFILT_READ | EV_DISPATCH | EV_ONESHOT); setpollEvents(rcon,EVFILT_READ | EV_ONESHOT); }catch(NetException &e){ if(e.getErrorType()== NetException::Note){ Loading Loading @@ -262,7 +262,7 @@ namespace netplus { }catch(NetException &e){ if(e.getErrorType()== NetException::Note){ wcon->state=EVOUT; setpollEvents(wcon,EVFILT_WRITE | EV_DISPATCH | EV_ONESHOT); setpollEvents(wcon,EVFILT_WRITE | EV_ONESHOT); return; }else{ throw e; Loading
src/posix/socket.cpp +18 −18 Original line number Diff line number Diff line Loading @@ -149,16 +149,16 @@ netplus::tcp::~tcp(){ } netplus::tcp::tcp() { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); _SocketPtr=::malloc(sizeof(struct sockaddr)); _SocketPtrSize=sizeof(struct sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _Socket=::socket(((struct sockaddr*)_SocketPtr)->sa_family,SOCK_STREAM,0);; _Type=sockettype::TCP; } netplus::tcp::tcp(int sock) { _SocketPtr=::malloc(sizeof(sockaddr)); _SocketPtrSize=sizeof(sockaddr); _SocketPtr=::malloc(sizeof(struct sockaddr)); _SocketPtrSize=sizeof(struct sockaddr); ((struct sockaddr*)_SocketPtr)->sa_family=AF_UNSPEC; _Socket=sock; _Type=sockettype::TCP; Loading Loading @@ -189,9 +189,10 @@ int netplus::tcp::getMaxconnections(){ void netplus::tcp::accept(socket *csock){ NetException exception; struct sockaddr myaddr; socklen_t myaddrlen=sizeof(myaddr); *csock=::accept(_Socket,(struct sockaddr *)&myaddr,&myaddrlen); *csock=::accept(_Socket,(struct sockaddr *)csock->_SocketPtr, &csock->_SocketPtrSize); if(csock->_Socket<0){ int etype=NetException::Error; if(errno==EAGAIN) Loading @@ -202,9 +203,6 @@ void netplus::tcp::accept(socket *csock){ exception[etype] << "Can't accept on Socket: " << errstr; throw exception; } csock->_SocketPtrSize = myaddrlen; csock->_SocketPtr = malloc(myaddrlen); memcpy(csock->_SocketPtr,&myaddr,myaddrlen); } void netplus::tcp::bind(){ Loading @@ -219,17 +217,19 @@ void netplus::tcp::bind(){ unsigned int netplus::tcp::sendData(socket *csock, void* data, unsigned long size){ return sendData(csock,data,size,0); } #include <iostream> unsigned int netplus::tcp::sendData(socket *csock, void* data, unsigned long size,int flags){ NetException exception; int rval=::sendto(csock->_Socket, std::cout << (unsigned int)csock->_SocketPtrSize <<std::endl; int rval=::sendto(csock->fd(), data, size, flags, (struct sockaddr *)&csock->_SocketPtr, csock->_SocketPtrSize (struct sockaddr *)csock->_SocketPtr, sizeof(struct sockaddr) ); if(rval<0){ int etype=NetException::Error; Loading @@ -254,11 +254,11 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz NetException exception; int recvsize=::recvfrom(csock->_Socket, int recvsize=::recvfrom(csock->fd(), data, size, flags, (struct sockaddr *)&csock->_SocketPtr, (struct sockaddr *)csock->_SocketPtr, &csock->_SocketPtrSize ); if(recvsize<0){ Loading @@ -277,6 +277,7 @@ unsigned int netplus::tcp::recvData(socket *csock, void* data, unsigned long siz } return recvsize; } void netplus::tcp::connect(socket *csock){ NetException exception; Loading @@ -290,7 +291,6 @@ void netplus::tcp::connect(socket *csock){ } } void netplus::tcp::getAddress(std::string &addr){ if(!_SocketPtr) return; Loading