C++ style copy and set

This commit is contained in:
Peter Thorson
2012-03-18 14:33:13 -05:00
parent 41cd2ac01e
commit ae12a9ee52
2 changed files with 10 additions and 6 deletions

View File

@@ -68,8 +68,10 @@ public:
decode_client_key(request.header("Sec-WebSocket-Key2"), &key_final[4]);
// copy key3 into final key
memcpy(&key_final[8],request.header("Sec-WebSocket-Key3").c_str(),8);
std::copy(request.header("Sec-WebSocket-Key3").c_str(),
request.header("Sec-WebSocket-Key3").c_str()+8,
&key_final[8]);
m_key3 = md5_hash_string(std::string(key_final,16));
response.add_header("Upgrade","websocket");
@@ -307,9 +309,11 @@ private:
num = atoi(digits.c_str());
if (spaces > 0 && num > 0) {
num = htonl(num/spaces);
memcpy(result, reinterpret_cast<char*>(&num), 4);
std::copy(reinterpret_cast<char*>(&num),
reinterpret_cast<char*>(&num)+4,
result);
} else {
memset(result, 0, 4);
std::fill(result,result+4,0);
}
}

View File

@@ -106,7 +106,7 @@ public:
m_bytes_needed = BASIC_HEADER_LENGTH;
m_degraded = false;
m_payload.clear();
memset(m_header,0,MAX_HEADER_LENGTH);
std::fill(m_header,m_header+MAX_HEADER_LENGTH,0);
}
// Method invariant: One of the following must always be true even in the case
@@ -337,7 +337,7 @@ public:
char val[2] = { m_payload[0], m_payload[1] };
uint16_t code;
memcpy(&code, val, sizeof(code));
std::copy(val,val+sizeof(code),&code);
code = ntohs(code);
return close::status::value(code);