| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 
 | //une struct vide, servant d'exception pour la socket
struct failed_socket {};
 
class raiied_skt {
private:
    skt_t* socket;
public:
    raiied_skt(const char* url) : socket (skt_open(url));{
        if(socket==NULL) throw failed_socket();
    }
    ~raiied_skt() {skt_close(socket);}
 
    raiied_skt& send(const char* buf, unsigned int n) {
        skt_send(socket, buf, n);
        return *this;
    }
 
    raiied_skt& send(std::vector<char> const& buf) {
        skt_send(socket, buf.data(), buf.size());
        return *this;
    }    
 
    raiied_skt& wait(char* buf, unsigned int n, unsigned int timer)  {
        skt_wait(socket, buf, n, timer);
        return *this;
    }
    raiied_skt& wait(std::vector<char>& buf, unsigned int n, unsigned int timer)  {
        skt_wait(socket, buf.data(), n, timer);
        return *this;
    }
}; | 
Partager