Commit 565a6a04 authored by jan.koester's avatar jan.koester
Browse files

test

parent 21c9b369
Loading
Loading
Loading
Loading
+5 −5
Changes for src/posix/tcp.cpp: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -153,7 +153,7 @@ int netplus::tcp::getMaxconnections(){
    return _Maxconnections;
}

void netplus::tcp::accept(socket *csock){
void netplus::tcp::accept(std::shared_ptr<socket>&csock){
    NetException exception;

    copyAddrInfo(&csock->_SocketInfo,_SocketInfo,_SocketInfoLen);
@@ -180,11 +180,11 @@ void netplus::tcp::bind(){
    }
}

size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){
size_t netplus::tcp::sendData(std::shared_ptr<char> &data,size_t size,int flags){

    NetException exception;

    int rval=::send(_Socket,data,size,flags);
    int rval=::send(_Socket,data.get(),size,flags);
    if(rval<0){
        int etype=NetException::Error;

@@ -203,11 +203,11 @@ size_t netplus::tcp::sendData(void* data, unsigned long size,int flags){
}


size_t netplus::tcp::recvData(void* data, unsigned long size,int flags){
size_t netplus::tcp::recvData(std::shared_ptr<char> &data,size_t size,int flags){
    NetException exception;

    int recvsize=::recv(_Socket,
                            data,
                            data.get(),
                            size,
                            flags
                        );
+30 −37
Changes for src/posix/udp.cpp: 30 added lines, 37 removed lines.
Original line number Diff line number Diff line
@@ -181,59 +181,52 @@ void netplus::udp::bind(){
    }
}

size_t netplus::udp::sendData(void* data, unsigned long size,int flags){
    WSABUF buf{ 0 };
size_t netplus::tcp::sendData(std::shared_ptr<char> &data,size_t size,int flags){

    buf.buf = (char*)data;
    buf.len = size;
    NetException exception;

    DWORD dwFlags = 0;
    DWORD dwsend = 0;
    SOCKET rval = ::WSASend(_Socket, &buf, 1, nullptr, flags, &_Overlapped, nullptr);
    int rval=::send(_Socket,data.get(),size,flags);
    if(rval<0){
        int etype=NetException::Error;

    if (rval == SOCKET_ERROR) {
        DWORD lerror = GetLastError();
        if(errno==EAGAIN || errno==EWOULDBLOCK)
            etype=NetException::Note;

        if (lerror == WSA_IO_PENDING) {
            return (size_t)buf.len;
        }
        else {
            NetException exception;
            exception[NetException::Error] << "Socket senddata failed on Socket: " << (int)_Socket
                << " ErrorMsg: " << lerror;
        char errstr[512];
        strerror_r_netplus(errno,errstr,512);

        exception[etype] << "Socket senddata failed on Socket: " << _Socket
                                       << " ErrorMsg: " <<  errstr;
        throw exception;
    }
    }
    return (size_t)buf.len;

    return (size_t) rval != 0 ? rval : size;
}

size_t netplus::udp::recvData(void* data, unsigned long size,int flags){
    NetException exception;

    WSABUF buf;
size_t netplus::tcp::recvData(std::shared_ptr<char> &data,size_t size,int flags){
    NetException exception;

    buf.buf = reinterpret_cast<char*>(data);
    buf.len = size;
    int recvsize=::recv(_Socket,
                            data.get(),
                            size,
                            flags
                        );
    if(recvsize<0){
        int etype=NetException::Error;

    DWORD dwFlags = 0;
    DWORD dwBytes = 0;
        if(errno==EAGAIN || errno==EWOULDBLOCK)
            etype=NetException::Note;

    int recvsize = ::WSARecv(_Socket, &buf, 1, &dwBytes, (LPDWORD)&flags, &_Overlapped, nullptr);

    if (recvsize == SOCKET_ERROR) {
        DWORD lerror = WSAGetLastError();
        char errstr[512];
        strerror_r_netplus(errno,errstr,512);

        if (lerror != WSA_IO_PENDING) {
            exception[NetException::Error] << "Socket recvdata failed on Socket: " << (int)_Socket
                << " ErrorMsg: " << lerror;
        exception[etype] << "Socket recvdata failed on Socket: " << _Socket
                                       << " ErrorMsg: " <<  errstr;
        throw exception;
    }
        else {
            return buf.len;
        }
    }

    return (size_t)buf.len;
    return (size_t)recvsize != 0 ? recvsize : size;
}

void netplus::udp::connect(socket *ssock){
+9 −9
Changes for src/socket.h: 9 added lines, 9 removed lines.
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ namespace netplus {

            virtual int              getMaxconnections()=0;
            
            virtual size_t           sendData(void *data, unsigned long size,int flags=0)=0;
            virtual size_t           recvData(void *data, unsigned long size,int flags=0)=0;
            virtual size_t sendData(std::shared_ptr<char> &data,size_t size,int flags=0);
            virtual size_t recvData(std::shared_ptr<char> &data,size_t size,int flags=0);

            virtual void             connect(socket *csock)=0;

@@ -110,8 +110,8 @@ namespace netplus {

            int           getMaxconnections();
            
            size_t sendData(void *data,unsigned long size,int flags=0);
            size_t recvData(void *data,unsigned long size,int flags=0);
            size_t sendData(std::shared_ptr<char> &data,size_t size,int flags=0);
            size_t recvData(std::shared_ptr<char> &data,size_t size,int flags=0);

            virtual void connect(socket *csock);

@@ -144,8 +144,8 @@ namespace netplus {

            int           getMaxconnections();

            size_t sendData(void *data,unsigned long size,int flags=0);
            size_t recvData(void *data,unsigned long size,int flags=0);
            size_t sendData(std::shared_ptr<char> &data,size_t size,int flags=0);
            size_t recvData(std::shared_ptr<char> &data,size_t size,int flags=0);

            void connect(socket *csock);

@@ -166,13 +166,13 @@ namespace netplus {
                int sockopts,const unsigned char *cert,size_t certlen,const unsigned char *key, size_t keylen);
            ~ssl();
            
            void          accept(socket *ssock);
            void          accept(std::shared_ptr<socket> &csock);

            ssl&          operator=(int socket);
            int           getMaxconnections();
            
            size_t        sendData(void *data,unsigned long size,int flags=0);
            size_t        recvData(void *data,unsigned long size,int flags=0);
            size_t sendData(std::shared_ptr<char> &data,size_t size,int flags=0);
            size_t recvData(std::shared_ptr<char> &data,size_t size,int flags=0);
            
            void connect(socket *csock);
            void getAddress(std::string &addr);
+1 −12
Changes for src/ssl.cpp: 1 added line, 12 removed lines.
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ netplus::ssl::ssl() : tcp(){
netplus::ssl::~ssl(){
}

void netplus::ssl::accept(socket *csock){
void netplus::ssl::accept(std::shared_ptr<socket> &csock){
}

netplus::ssl& netplus::ssl::operator=(int sock){
@@ -51,14 +51,3 @@ size_t netplus::ssl::recvData(void *data,unsigned long size,int flags){
void netplus::ssl::connect(socket *ssock){
}
void netplus::ssl::getAddress(std::string &addr){
    // if(!_SocketInfo)
    //     return;
    // char ipaddr[INET6_ADDRSTRLEN];
    // if(((struct sockaddr*)_SocketInfo)->sa_family==AF_INET6)
    //     inet_ntop(AF_INET6, &(((struct sockaddr_in6*)_SocketInfo)->sin6_addr), ipaddr, INET6_ADDRSTRLEN);
    // else
    //     inet_ntop(AF_INET, &((struct sockaddr_in*)_SocketInfo)->sin_addr, ipaddr, INET_ADDRSTRLEN);
    // addr=ipaddr;
}