Search
 
SCRIPT & CODE EXAMPLE
 

CPP

c/c++ windows api socket wrappers

namespace wrappers {
    ssize_t sender_wrapper(SOCKET &sock, char *buff, size_t size) {
        size_t sent = 0;
        ssize_t result = 0;

        do {
            result = send(sock, buff, size, 0);
            if (result > 0) {
                buff += result;
                size -= (size_t) result;
            } else if (result == 0) {
                // remote disconnected
            } else {
                // error
            }
        } while (result > 0 && size > 0);
        return result;
    }
    ssize_t receive_wrapper(SOCKET &sock, char *buff, size_t size) {
        size_t recved = 0;
        ssize_t result = 0;

        do {
            result = recv(sock, buff, size, 0);
            if (result > 0) {
                buff += result;
                size -= (size_t) result;
            } else if (result == 0) {
                return -1;
            } else {
                return -1;
                // error
            }
        } while (result > 0 && size > 0);

        return result;
    }
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: cin does not wait for input 
Cpp :: log base e synthax c++ 
Cpp :: closing a ifstream file c++ 
Cpp :: c++ queue 
Cpp :: if else in c++ 
Cpp :: integer max value c++ 
Cpp :: 2d array of zeros c++ 
Cpp :: Accessing C++ Array Elements 
Cpp :: how can I delete a substring from a string in c++? 
Cpp :: remove element from c++ 
Cpp :: how to use power in c++ 
Cpp :: Maximum sum of non consecutive elements 
Cpp :: options select from array 
Cpp :: c++ switch case 
Cpp :: c++ check first character of string 
Cpp :: cpp language explained 
Cpp :: c++ structs 
Cpp :: bitmap 
Cpp :: Check whether the jth object is in the subset 
Cpp :: Numbers Histogram in c++ 
Cpp :: Common elements gfg in c++ 
Cpp :: how to run cpp in visual studio 
Cpp :: c++ graphics online compiler 
Cpp :: C++ Relational Operators 
Cpp :: setFontSize QT 
Cpp :: what c++ library is arccos in 
Cpp :: overwrite windows mbr c++ 
Cpp :: how to type cast quotient of two integers to double with c++ 
Cpp :: vector literal in cpp 
Cpp :: product of array in cpp 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =