Ev'ryday I'm bufferin'.

This commit is contained in:
Marc-Eric Martel
2023-10-27 09:51:40 -04:00
parent 0bc7f29492
commit 9ef44a3993
4 changed files with 82 additions and 50 deletions

View File

@@ -20,7 +20,7 @@ namespace netprot {
struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
char* ptr = new char[BUFFER_LENGTH];
int32_t len = BUFFER_LENGTH;
uint32_t len = BUFFER_LENGTH;
~Buffer() { delete[] ptr; }
void rstLen() { len = BUFFER_LENGTH; }
@@ -157,7 +157,7 @@ namespace netprot {
template <class T>
void sendPack(SOCKET sock, T* pack, Buffer* buf) {
netprot::Serialize(pack, buf->ptr, buf->len);
netprot::Serialize(pack, &buf->ptr, &buf->len);
send(sock, buf->ptr, buf->len, 0);
buf->rstLen();
}
@@ -165,7 +165,7 @@ namespace netprot {
template <class T>
void sendPackTo(SOCKET sock, T* pack, Buffer* buf, sockaddr_in* sockad) {
sockaddr_in addr = *sockad;
netprot::Serialize(pack, buf->ptr, buf->len);
netprot::Serialize(pack, &buf->ptr, &buf->len);
sendto(sock, buf->ptr, buf->len, 0, (sockaddr*)&addr, sizeof(addr));
buf->rstLen();
}