😠
This commit is contained in:
parent
408679433b
commit
2753e41d34
@ -952,16 +952,25 @@ netprot::Packet netprot::makePack(void* ptr, PACKET_TYPE type) {
|
||||
|
||||
std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||
std::vector<char*> lsPck;
|
||||
int len = 0, end = 0;
|
||||
char * cursor = nullptr, * next = buf->ptr, * last = buf->ptr;
|
||||
int len = buf->tmp? buf->tmp - buf->ptr: 0,
|
||||
end = 0;
|
||||
char * cursor = buf->tmp ? buf->tmp: nullptr ,
|
||||
* next = buf->tmp ? buf->tmp + 1: buf->ptr,
|
||||
* last = buf->tmp ? buf->tmp: buf->ptr;
|
||||
bool ended = true;
|
||||
|
||||
while (true) {
|
||||
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
|
||||
if (bytes <= 0) // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
|
||||
if (bytes <= 0) { // si recv() retourne -1 ou 0; ça veut dire qu'il y a plus rien a lire qui n'a pas déjà été traité.
|
||||
if (ended)
|
||||
buf->tmp = nullptr;
|
||||
return lsPck;
|
||||
}
|
||||
len += bytes;
|
||||
end = len;
|
||||
|
||||
ended = false;
|
||||
|
||||
while (true) {
|
||||
int cmp = 0;
|
||||
|
||||
@ -986,6 +995,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||
}
|
||||
}
|
||||
else {
|
||||
buf->tmp = last;
|
||||
cursor = &buf->ptr[len];
|
||||
next = cursor + 1;
|
||||
break;
|
||||
|
@ -19,7 +19,7 @@ namespace netprot {
|
||||
/* Structures */
|
||||
|
||||
struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
|
||||
char* ptr = new char[BUFFER_LENGTH] { 1 };
|
||||
char* ptr = new char[BUFFER_LENGTH] { 1 }, * tmp = nullptr;
|
||||
uint32_t len = BUFFER_LENGTH;
|
||||
|
||||
~Buffer() { delete[] ptr; }
|
||||
|
@ -170,7 +170,7 @@
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
@ -192,7 +192,7 @@
|
||||
<FloatingPointModel>Fast</FloatingPointModel>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
|
Loading…
Reference in New Issue
Block a user