source: trunk/CrypPlugins/KeySearcher/ExternalClient/PlatformIndependentWrapper.cpp @ 2205

Last change on this file since 2205 was 2205, checked in by Sven Rech, 11 years ago

Added external client for other plattforms which can be used to support the keysearcher (client doesn't work yet)

File size: 1.1 KB
Line 
1#include <sys/types.h>
2#include <arpa/inet.h>
3#include <stdio.h>
4
5#include "PlatformIndependentWrapper.h"
6
7std::string PlatformIndependentWrapper::ReadString()
8{
9    int32_t strlen = ReadInt();
10    char str[strlen];
11    ReadArray(str, strlen);
12    std::string ret = std::string(str, strlen);
13    return ret;
14}
15
16void PlatformIndependentWrapper::WriteString(std::string str)
17{
18    int strlen = str.length();
19    WriteInt(strlen);
20    WriteArray(str.c_str(), strlen);
21}
22
23int32_t PlatformIndependentWrapper::ReadInt()
24{
25    char buf[4];
26    ReadArray(buf, 4);
27    return ntohl(*((int*)buf));
28}
29
30void PlatformIndependentWrapper::WriteInt(int32_t i)
31{
32    int networked = htonl(i);
33    WriteArray((char*)(&networked), 4);
34}
35
36void PlatformIndependentWrapper::ReadArray(char* buf, int num)
37{
38    int rec = 0;
39    int offset = 0;
40    do{
41        rec = read(this->sockfd, buf+offset, num-offset);
42        offset += rec;
43    } while(rec > 0 && offset< num);
44
45    if(rec < 0)
46    {
47        throw SocketException();
48    }
49}
50
51void PlatformIndependentWrapper::WriteArray(const char* buf, int num)
52{
53    write(this->sockfd, buf, num);
54}
Note: See TracBrowser for help on using the repository browser.