tFixes for new networking code with Windows Sockets - vaccinewars - be a doctor and try to vaccinate the world
(HTM) git clone git://src.adamsgaard.dk/vaccinewars
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
(DIR) commit 275f3dd7e8490d3e45d805a7ce1736d5d17f5d7d
(DIR) parent df1ddce3e211ed4a7aa28dde40ef79dc44bd53b1
(HTM) Author: Ben Webb <ben@salilab.org>
Date: Sun, 12 Nov 2000 15:16:29 +0000
Fixes for new networking code with Windows Sockets
Diffstat:
M config.h.in | 3 +++
M src/dopeos.c | 2 ++
M src/dopeos.h | 5 +++++
M src/message.c | 15 +++++++++++----
M src/win32_client.c | 12 +++++++-----
5 files changed, 28 insertions(+), 9 deletions(-)
---
(DIR) diff --git a/config.h.in b/config.h.in
t@@ -99,6 +99,9 @@
/* Define if you have the getcwd function. */
#undef HAVE_GETCWD
+/* Define if you have the gethostbyname function. */
+#undef HAVE_GETHOSTBYNAME
+
/* Define if you have the getpagesize function. */
#undef HAVE_GETPAGESIZE
(DIR) diff --git a/src/dopeos.c b/src/dopeos.c
t@@ -274,6 +274,7 @@ int bselect(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,
}
#if NETWORKING
+int GetSocketError() { return WSAGetLastError(); }
void fcntl(SOCKET s,int fsetfl,long cmd) {
unsigned long param=1;
ioctlsocket(s,cmd,¶m);
t@@ -323,6 +324,7 @@ int bgetch() {
#endif
#if NETWORKING
+int GetSocketError() { return errno; }
void StartNetworking() {}
void StopNetworking() {}
void SetReuse(int sock) {
(DIR) diff --git a/src/dopeos.h b/src/dopeos.h
t@@ -116,6 +116,7 @@ int bselect(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfs,
struct timeval *tm);
#if NETWORKING
+int GetSocketError();
void fcntl(SOCKET s,int fsetfl,long cmd);
#define CloseSocket(sock) closesocket(sock)
void StartNetworking();
t@@ -133,6 +134,7 @@ void SetReuse(SOCKET sock);
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
+#include <errno.h>
#endif /* NETWORKING */
/* Only include sys/wait.h on those systems which support it */
t@@ -172,9 +174,12 @@ int bgetch();
#if NETWORKING
#define CloseSocket(sock) close(sock)
+int GetSocketError();
void StartNetworking();
void StopNetworking();
void SetReuse(int sock);
+#define WSAECONNRESET EPIPE
+#define WSAEWOULDBLOCK EINPROGRESS
#endif /* NETWORKING */
#endif /* CYGWIN */
(DIR) diff --git a/src/message.c b/src/message.c
t@@ -29,12 +29,14 @@
#include <fcntl.h>
#endif
+#ifndef CYGWIN
#include <sys/types.h>
#include <sys/socket.h>
+#endif
+
#include <string.h>
#include <stdlib.h>
#include <glib.h>
-#include <errno.h>
#include "dopeos.h"
#include "dopewars.h"
#include "serverside.h"
t@@ -370,7 +372,7 @@ gboolean WriteConnectionBufferToWire(Player *Play) {
BytesSent=send(Play->fd,&conn->Data[CurrentPosition],
conn->DataPresent-CurrentPosition,0);
if (BytesSent==SOCKET_ERROR) {
- if (errno==EPIPE) return FALSE;
+ if (GetSocketError()==WSAECONNRESET) return FALSE;
break;
} else {
CurrentPosition+=BytesSent;
t@@ -704,7 +706,7 @@ char *SetupNetwork(gboolean NonBlocking) {
if (NonBlocking) fcntl(ClientSock,F_SETFL,O_NONBLOCK);
if (connect(ClientSock,(struct sockaddr *)&ClientAddr,
sizeof(struct sockaddr))==-1) {
- if (errno==EINPROGRESS) return NULL;
+ if (GetSocketError()==WSAEWOULDBLOCK) return NULL;
CloseSocket(ClientSock);
return NoConnect;
} else {
t@@ -715,9 +717,13 @@ char *SetupNetwork(gboolean NonBlocking) {
}
char *FinishSetupNetwork() {
- socklen_t optlen;
+#ifdef CYGWIN
+ Client=Network=TRUE;
+ return NULL;
+#else
int optval;
static char NoConnect[]= N_("Connection refused or no server present");
+ socklen_t optlen;
optlen=sizeof(optval);
if (getsockopt(ClientSock,SOL_SOCKET,SO_ERROR,&optval,&optlen)==-1) {
t@@ -729,6 +735,7 @@ char *FinishSetupNetwork() {
} else {
return NoConnect;
}
+#endif
}
#endif /* NETWORKING */
(DIR) diff --git a/src/win32_client.c b/src/win32_client.c
t@@ -32,6 +32,7 @@
#include "dopeos.h"
#include "dopewars.h"
+#include "tstring.h"
#include "curses_client.h"
#include "win32_client.h"
#include "message.h"
t@@ -95,6 +96,8 @@ static void DisplaySpyReports(Player *Play);
static void CreateStats(HWND hwnd,struct STATS *Stats,
gboolean CreateEdit,gboolean CreateButtons);
static void SizeStats(HWND hwnd,struct STATS *Stats,RECT *rect);
+static void SizeStats(HWND hwnd,struct STATS *Stats,RECT *rect);
+static void SizeStats(HWND hwnd,struct STATS *Stats,RECT *rect);
static void ShowStats(struct STATS *Stats,int State);
static void LogMessage(const gchar *log_domain,GLogLevelFlags log_level,
t@@ -104,7 +107,6 @@ static void LogMessage(const gchar *log_domain,GLogLevelFlags log_level,
}
static void DisplayStats(Player *Play,struct STATS *Stats) {
- gchar *prstr,*caps;
GString *text;
text=g_string_new("");
t@@ -166,8 +168,8 @@ void UpdateInventory(HWND HereList,HWND CarriedList,
Player *Play;
gint i;
price_t price;
- gchar *name,*prstr,*text;
LRESULT addresult;
+ gchar *name,*text;
gboolean CanBuy=FALSE,CanSell=FALSE,CanDrop=FALSE;
Play=ClientData.Play;
t@@ -754,14 +756,15 @@ BOOL CALLBACK TransferWndProc(HWND hwnd,UINT msg,UINT wParam,
static char Type;
HWND MoneyWnd;
int buflen;
+ gchar *prstr;
price_t money;
- gchar *text,*prstr;
+ gchar *text;
switch(msg) {
case WM_INITDIALOG:
Type=(char)lParam;
text=dpg_strdup_printf("Cash: %P",ClientData.Play->Cash);
SetDlgItemText(hwnd,ST_MONEY,text);
- g_free(text); g_free(prstr);
+ g_free(text);
if (Type==C_BANK) {
CheckDlgButton(hwnd,RB_WITHDRAW,BST_CHECKED);
text=dpg_strdup_printf("Bank: %P",ClientData.Play->Bank);
t@@ -1775,7 +1778,6 @@ int APIENTRY Win32Loop(HINSTANCE hInstance,HINSTANCE hPrevInstance,
while(GetMessage(&msg,NULL,0,0)) {
if ((!PlayerListWnd || !IsDialogMessage(PlayerListWnd,&msg)) &&
(!TalkWnd || !IsDialogMessage(TalkWnd,&msg)) &&
- (!InventoryWnd || !IsDialogMessage(InventoryWnd,&msg)) &&
(!FightWnd || !IsDialogMessage(FightWnd,&msg)) &&
(!GunShopWnd || !IsDialogMessage(GunShopWnd,&msg)) &&
(!SpyReportsWnd || !IsDialogMessage(SpyReportsWnd,&msg)) &&