😠
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*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
||||||
std::vector<char*> lsPck;
|
std::vector<char*> lsPck;
|
||||||
int len = 0, end = 0;
|
int len = buf->tmp? buf->tmp - buf->ptr: 0,
|
||||||
char * cursor = nullptr, * next = buf->ptr, * last = buf->ptr;
|
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) {
|
while (true) {
|
||||||
int bytes = recv(sock, &buf->ptr[len], buf->len - len, 0);
|
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;
|
return lsPck;
|
||||||
|
}
|
||||||
len += bytes;
|
len += bytes;
|
||||||
end = len;
|
end = len;
|
||||||
|
|
||||||
|
ended = false;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
int cmp = 0;
|
int cmp = 0;
|
||||||
|
|
||||||
@ -986,6 +995,7 @@ std::vector<char*> netprot::recvPacks(SOCKET sock, Buffer* buf) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
buf->tmp = last;
|
||||||
cursor = &buf->ptr[len];
|
cursor = &buf->ptr[len];
|
||||||
next = cursor + 1;
|
next = cursor + 1;
|
||||||
break;
|
break;
|
||||||
|
@ -19,7 +19,7 @@ namespace netprot {
|
|||||||
/* Structures */
|
/* Structures */
|
||||||
|
|
||||||
struct Buffer { // Pour pouvoir rendre l'utilisation des buffers plus clean.
|
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;
|
uint32_t len = BUFFER_LENGTH;
|
||||||
|
|
||||||
~Buffer() { delete[] ptr; }
|
~Buffer() { delete[] ptr; }
|
||||||
|
@ -170,7 +170,7 @@
|
|||||||
<FloatingPointModel>Fast</FloatingPointModel>
|
<FloatingPointModel>Fast</FloatingPointModel>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
@ -192,7 +192,7 @@
|
|||||||
<FloatingPointModel>Fast</FloatingPointModel>
|
<FloatingPointModel>Fast</FloatingPointModel>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Windows</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>false</GenerateDebugInformation>
|
<GenerateDebugInformation>false</GenerateDebugInformation>
|
||||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||||
<OptimizeReferences>true</OptimizeReferences>
|
<OptimizeReferences>true</OptimizeReferences>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user