Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
Fixed socket communication.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed Jun 13, 2017
1 parent 76dc250 commit e2bcaf3
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions Compiler/runtime/socketimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,32 @@ static struct sockaddr_in clientAddr;
static int
make_socket (unsigned short int port)
{
#if defined(__MINGW32__) || defined(_MSC_VER)
// Winsock.DLL Initialization
WORD wVersionRequested;
WSADATA wsaData;
wVersionRequested = MAKEWORD(1, 1);
if (WSAStartup (wVersionRequested, &wsaData) != 0) {
printf("Failed to start the windows sockets!\n");
return 0;
}
#endif

int sock;
struct sockaddr_in name;
socklen_t optlen;
int one=1;

/* Create the socket. */
sock = socket (PF_INET, SOCK_STREAM, 0);
sock = socket (AF_INET, SOCK_STREAM, 0);
if (sock < 0)
{
printf("Error creating socket\n");
return 0;
}

/* Give the socket a name. */
name.sin_family = PF_INET;
name.sin_family = AF_INET;
name.sin_port = htons (port);
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char*)&one,sizeof(int))) {
Expand Down Expand Up @@ -139,7 +150,12 @@ extern int Socket_waitforconnect(int port)
return -1;
}

#if defined(__MINGW32__) || defined(_MSC_VER)
int addr_length = sizeof(clientAddr);
ns = accept(serversocket,(struct sockaddr *)&clientAddr, (int*)&addr_length);
#else
ns = accept(serversocket,(struct sockaddr *)&clientAddr,&fromlen);
#endif

if (ns < 0) {
const char *tokens[1] = {strerror(errno)};
Expand Down

0 comments on commit e2bcaf3

Please sign in to comment.