mirror of
https://github.com/EQEmu/Server.git
synced 2026-03-23 10:42:25 +00:00
Fixed memory allocation for socket write, stopgap for now we can probably set a max message out size and cut out allocations all together.
This commit is contained in:
parent
e0bc0e2e5c
commit
5ad7b84415
@ -53,6 +53,7 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
|||||||
session->send_queue = new std::list<std::string>();
|
session->send_queue = new std::list<std::string>();
|
||||||
break;
|
break;
|
||||||
case LWS_CALLBACK_RECEIVE: {
|
case LWS_CALLBACK_RECEIVE: {
|
||||||
|
|
||||||
//recv and parse commands here
|
//recv and parse commands here
|
||||||
if(len < 1)
|
if(len < 1)
|
||||||
break;
|
break;
|
||||||
@ -68,7 +69,12 @@ int callback_eqemu(libwebsocket_context *context, libwebsocket *wsi, libwebsocke
|
|||||||
case LWS_CALLBACK_SERVER_WRITEABLE:
|
case LWS_CALLBACK_SERVER_WRITEABLE:
|
||||||
//send stuff here
|
//send stuff here
|
||||||
for (auto iter = session->send_queue->begin(); iter != session->send_queue->end(); ++iter) {
|
for (auto iter = session->send_queue->begin(); iter != session->send_queue->end(); ++iter) {
|
||||||
auto n = libwebsocket_write(wsi, (unsigned char*)&(*iter)[0], (*iter).size(), LWS_WRITE_TEXT);
|
size_t sz = LWS_SEND_BUFFER_PRE_PADDING + LWS_SEND_BUFFER_POST_PADDING + (*iter).size();
|
||||||
|
unsigned char *buf = new unsigned char[sz];
|
||||||
|
memset(buf, 0, sz);
|
||||||
|
memcpy(&buf[LWS_SEND_BUFFER_PRE_PADDING], &(*iter)[0], (*iter).size());
|
||||||
|
auto n = libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], (*iter).size(), LWS_WRITE_TEXT);
|
||||||
|
delete[] buf;
|
||||||
if (n < (*iter).size()) {
|
if (n < (*iter).size()) {
|
||||||
//couldn't write the message
|
//couldn't write the message
|
||||||
return -1;
|
return -1;
|
||||||
@ -126,7 +132,7 @@ int main() {
|
|||||||
|
|
||||||
worldserver = new WorldServer(config->SharedKey);
|
worldserver = new WorldServer(config->SharedKey);
|
||||||
worldserver->Connect();
|
worldserver->Connect();
|
||||||
writable_socket_timer.Start(50);
|
writable_socket_timer.Start(10);
|
||||||
|
|
||||||
while(run) {
|
while(run) {
|
||||||
Timer::SetCurrentTime();
|
Timer::SetCurrentTime();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user