Fixed some pretty bad socket issues
Fixed some bad socket issues that sockets were created non-blocking but wasn't handled correctly for that case. Now we create blocking ones (like the old editor) so hopefully everything should work better regarding getting/sending data Closes #68 Closes #69
This commit is contained in:
parent
184ea0bcb3
commit
731a90fc0a
@ -252,7 +252,7 @@ static int getPrevTrack()
|
|||||||
void Editor_create()
|
void Editor_create()
|
||||||
{
|
{
|
||||||
int id;
|
int id;
|
||||||
Emgui_create("foo");
|
Emgui_create();
|
||||||
id = Emgui_loadFontBitmap(g_minecraftiaFont, g_minecraftiaFontSize, EMGUI_LOCATION_MEMORY, 32, 128, g_minecraftiaFontLayout);
|
id = Emgui_loadFontBitmap(g_minecraftiaFont, g_minecraftiaFontSize, EMGUI_LOCATION_MEMORY, 32, 128, g_minecraftiaFontLayout);
|
||||||
|
|
||||||
RemoteConnection_createListner();
|
RemoteConnection_createListner();
|
||||||
@ -752,30 +752,13 @@ static int processCommands()
|
|||||||
|
|
||||||
case SET_ROW:
|
case SET_ROW:
|
||||||
{
|
{
|
||||||
int i = 0;
|
//int i = 0;
|
||||||
ret = RemoteConnection_recv((char*)&newRow, sizeof(int), 0);
|
ret = RemoteConnection_recv((char*)&newRow, sizeof(int), 0);
|
||||||
|
|
||||||
if (ret == -1)
|
if (ret)
|
||||||
{
|
|
||||||
// retry to get the data and do it for max of 20 times otherwise disconnect
|
|
||||||
|
|
||||||
for (i = 0; i < 20; ++i)
|
|
||||||
{
|
|
||||||
if (RemoteConnection_recv((char*)&newRow, sizeof(int), 0) == 4)
|
|
||||||
{
|
|
||||||
viewInfo->rowPos = htonl(newRow);
|
|
||||||
viewInfo->selectStartRow = viewInfo->selectStopRow = viewInfo->rowPos;
|
|
||||||
|
|
||||||
rlog(R_INFO, "row from demo %d\n", s_editorData.trackViewInfo.rowPos);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
viewInfo->rowPos = htonl(newRow);
|
viewInfo->rowPos = htonl(newRow);
|
||||||
viewInfo->selectStartRow = viewInfo->selectStopRow = viewInfo->rowPos;
|
viewInfo->selectStartRow = viewInfo->selectStopRow = viewInfo->rowPos;
|
||||||
|
|
||||||
rlog(R_INFO, "row from demo %d\n", s_editorData.trackViewInfo.rowPos);
|
rlog(R_INFO, "row from demo %d\n", s_editorData.trackViewInfo.rowPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -110,22 +110,6 @@ void RemoteConnection_mapTrackName(const char* name)
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
static bool setBlocking(int sock, bool blocking)
|
|
||||||
{
|
|
||||||
u_long block = blocking ? 0 : 1;
|
|
||||||
#if defined(_WIN32)
|
|
||||||
int error = ioctlsocket(sock, FIONBIO, &block);
|
|
||||||
#else
|
|
||||||
int error = ioctl(sock, FIONBIO, &block);
|
|
||||||
#endif
|
|
||||||
if (SOCKET_ERROR == error)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
bool RemoteConnection_createListner()
|
bool RemoteConnection_createListner()
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
@ -164,8 +148,6 @@ bool RemoteConnection_createListner()
|
|||||||
while (listen(s_serverSocket, SOMAXCONN) == -1)
|
while (listen(s_serverSocket, SOMAXCONN) == -1)
|
||||||
;
|
;
|
||||||
|
|
||||||
setBlocking(s_serverSocket, false);
|
|
||||||
|
|
||||||
rlog(R_INFO, "Created listner\n");
|
rlog(R_INFO, "Created listner\n");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -213,14 +195,23 @@ static SOCKET clientConnect(SOCKET serverSocket, struct sockaddr_in* host)
|
|||||||
|
|
||||||
void RemoteConnection_updateListner(int currentRow)
|
void RemoteConnection_updateListner(int currentRow)
|
||||||
{
|
{
|
||||||
SOCKET clientSocket;
|
struct timeval timeout;
|
||||||
struct sockaddr_in client;
|
struct sockaddr_in client;
|
||||||
|
SOCKET clientSocket = INVALID_SOCKET;
|
||||||
|
fd_set fds;
|
||||||
|
|
||||||
|
FD_ZERO(&fds);
|
||||||
|
FD_SET(s_serverSocket, &fds);
|
||||||
|
|
||||||
|
timeout.tv_sec = 0;
|
||||||
|
timeout.tv_usec = 0;
|
||||||
|
|
||||||
if (RemoteConnection_connected())
|
if (RemoteConnection_connected())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// look for new clients
|
// look for new clients
|
||||||
|
|
||||||
|
if (select(s_serverSocket + 1, &fds, NULL, NULL, &timeout) > 0)
|
||||||
{
|
{
|
||||||
clientSocket = clientConnect(s_serverSocket, &client);
|
clientSocket = clientConnect(s_serverSocket, &client);
|
||||||
|
|
||||||
@ -270,27 +261,11 @@ int RemoteConnection_recv(char* buffer, size_t length, int flags)
|
|||||||
|
|
||||||
ret = recv(s_socket, buffer, (int)length, flags);
|
ret = recv(s_socket, buffer, (int)length, flags);
|
||||||
|
|
||||||
#if defined(_WIN32)
|
if (ret != length)
|
||||||
if (ret <= 0)
|
|
||||||
{
|
|
||||||
int error = WSAGetLastError();
|
|
||||||
if (error == WSAEWOULDBLOCK)
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
{
|
||||||
RemoteConnection_disconnect();
|
RemoteConnection_disconnect();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (ret == 0)
|
|
||||||
{
|
|
||||||
RemoteConnection_disconnect();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user