Commit 30f2e910 authored by jan.koester's avatar jan.koester
Browse files

small bugfix

parent 32c71c2b
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -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!";
@@ -163,6 +163,7 @@ namespace netplus {
            }

            _evtapi->CreateConnetion(&ccon);

            if(_ServerSocket->_Type==sockettype::TCP){
                ccon->csock=new tcp();
            }else if(_ServerSocket->_Type==sockettype::UDP){
@@ -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;
@@ -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);

@@ -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){
@@ -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;
+18 −18
Original line number Diff line number Diff line
@@ -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;
@@ -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)
@@ -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(){
@@ -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;
@@ -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){
@@ -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;

@@ -290,7 +291,6 @@ void netplus::tcp::connect(socket *csock){
    }
}


void netplus::tcp::getAddress(std::string &addr){
    if(!_SocketPtr)
        return;