Skip to content

Commit 0171d16

Browse files
committed
Fix compiler warnings
1 parent 47e08a2 commit 0171d16

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

Modelica_DeviceDrivers/Resources/Include/MDDUDPSocket.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525

2626
#include <windows.h>
2727
#include "../src/include/CompatibilityDefs.h"
28-
#include <stdio.h>
29-
#include <conio.h>
30-
#include <tchar.h>
3128

3229
#pragma comment( lib, "Ws2_32.lib" )
3330

@@ -56,15 +53,15 @@ DWORD WINAPI MDD_udpReceivingThread(LPVOID pUdp) {
5653
LeaveCriticalSection(&udp->receiveLock);
5754
if (socketError) {
5855
ModelicaFormatMessage("MDDUDPSocket.h: Receiving not possible, socket not valid.\n");
59-
ExitThread(SOCKET_ERROR);
56+
ExitThread(1);
6057
}
6158
}
6259
return 0;
6360
}
6461

6562
DllExport void * MDD_udpConstructor(int port, int bufferSize) {
6663

67-
int rc; /* Error variable */
64+
int rc; /* Error variable */
6865
WSADATA wsa;
6966
SOCKADDR_IN addr;
7067
DWORD id1;
@@ -79,23 +76,27 @@ DllExport void * MDD_udpConstructor(int port, int bufferSize) {
7976
udp->SocketID = socket(AF_INET,SOCK_DGRAM,0);
8077
if (udp->SocketID == INVALID_SOCKET) {
8178
free(udp);
79+
udp = NULL;
8280
rc = WSAGetLastError();
8381
WSACleanup();
8482
ModelicaFormatError("MDDUDPSocket.h: Error at socket(): %ld\n", rc);
83+
return udp;
8584
}
8685
udp->receiving = 1;
8786
udp->bufferSize = bufferSize;
8887
udp->receivedBytes = 0;
8988
addr.sin_family = AF_INET;
90-
addr.sin_port = htons(port);
89+
addr.sin_port = htons((u_short)port);
9190
addr.sin_addr.s_addr = INADDR_ANY;
9291

9392
if (port) {
9493
rc = bind(udp->SocketID,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));
9594
if (rc == INVALID_SOCKET) {
9695
free(udp);
96+
udp = NULL;
9797
WSACleanup();
9898
ModelicaFormatError("MDDUDPSocket.h: Error at bind(..) to port %d\n", port);
99+
return udp;
99100
}
100101
udp->receiveBuffer = (char*)calloc(bufferSize, 1);
101102
udp->receiveBufferExport = (char*)calloc(bufferSize, 1);
@@ -106,8 +107,10 @@ DllExport void * MDD_udpConstructor(int port, int bufferSize) {
106107
free(udp->receiveBuffer);
107108
free(udp->receiveBufferExport);
108109
free(udp);
110+
udp = NULL;
109111
WSACleanup();
110112
ModelicaError("MDDUDPSocket.h: Error creating UDP Receiver thread.\n");
113+
return udp;
111114
}
112115
ModelicaFormatMessage("MDDUDPSocket.h: Waiting for data on port %d.\n", port);
113116
}
@@ -125,9 +128,9 @@ DllExport void MDD_udpDestructor(void * p_udp) {
125128
if (rc == SOCKET_ERROR) {
126129
ModelicaFormatMessage("MDDUDPSocket.h: shutdown failed: %d\n", WSAGetLastError());
127130
}
128-
rc = closesocket(udp->SocketID);
131+
closesocket(udp->SocketID);
129132
if (udp->hThread) {
130-
DWORD dwEc = -1;
133+
DWORD dwEc = 1;
131134
while (GetExitCodeThread(udp->hThread, &dwEc) && dwEc == STILL_ACTIVE) {
132135
;
133136
}
@@ -146,7 +149,7 @@ DllExport void MDD_udpSend(void * p_udp, const char * ipAddress, int port,
146149
if (udp) {
147150
SOCKADDR_IN addr;
148151
addr.sin_family=AF_INET;
149-
addr.sin_port=htons(port);
152+
addr.sin_port=htons((u_short)port);
150153
addr.sin_addr.s_addr=inet_addr(ipAddress);
151154
sendto(udp->SocketID,data,dataSize,0,(SOCKADDR*)&addr,sizeof(SOCKADDR_IN));
152155
}

0 commit comments

Comments
 (0)