Skip to content

Commit e2bcaf3

Browse files
adeas31OpenModelica-Hudson
authored andcommitted
Fixed socket communication.
1 parent 76dc250 commit e2bcaf3

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Compiler/runtime/socketimpl.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,32 @@ static struct sockaddr_in clientAddr;
9292
static int
9393
make_socket (unsigned short int port)
9494
{
95+
#if defined(__MINGW32__) || defined(_MSC_VER)
96+
// Winsock.DLL Initialization
97+
WORD wVersionRequested;
98+
WSADATA wsaData;
99+
wVersionRequested = MAKEWORD(1, 1);
100+
if (WSAStartup (wVersionRequested, &wsaData) != 0) {
101+
printf("Failed to start the windows sockets!\n");
102+
return 0;
103+
}
104+
#endif
105+
95106
int sock;
96107
struct sockaddr_in name;
97108
socklen_t optlen;
98109
int one=1;
99110

100111
/* Create the socket. */
101-
sock = socket (PF_INET, SOCK_STREAM, 0);
112+
sock = socket (AF_INET, SOCK_STREAM, 0);
102113
if (sock < 0)
103114
{
104115
printf("Error creating socket\n");
105116
return 0;
106117
}
107118

108119
/* Give the socket a name. */
109-
name.sin_family = PF_INET;
120+
name.sin_family = AF_INET;
110121
name.sin_port = htons (port);
111122
name.sin_addr.s_addr = htonl (INADDR_ANY);
112123
if (setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,(char*)&one,sizeof(int))) {
@@ -139,7 +150,12 @@ extern int Socket_waitforconnect(int port)
139150
return -1;
140151
}
141152

153+
#if defined(__MINGW32__) || defined(_MSC_VER)
154+
int addr_length = sizeof(clientAddr);
155+
ns = accept(serversocket,(struct sockaddr *)&clientAddr, (int*)&addr_length);
156+
#else
142157
ns = accept(serversocket,(struct sockaddr *)&clientAddr,&fromlen);
158+
#endif
143159

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

0 commit comments

Comments
 (0)