(player_new, player_accept, update_wait, market_update) [_WIN32]:
Move assignment of hostaddr and hostname from player_new() to player_accept(). This solves the necessary of adding the socket include file to prototypes.h for player_new(). The socket include file creates a namespace conflict for WIN32.
This commit is contained in:
parent
9dfbf74785
commit
233181c50d
4 changed files with 16 additions and 16 deletions
|
@ -411,7 +411,7 @@ extern void global_init(void);
|
||||||
*/
|
*/
|
||||||
/* accept.c */
|
/* accept.c */
|
||||||
extern void player_init(void);
|
extern void player_init(void);
|
||||||
extern struct player *player_new(int, struct sockaddr_in *);
|
extern struct player *player_new(int);
|
||||||
extern struct player *player_delete(struct player *);
|
extern struct player *player_delete(struct player *);
|
||||||
extern struct player *player_next(struct player *);
|
extern struct player *player_next(struct player *);
|
||||||
extern struct player *player_prev(struct player *);
|
extern struct player *player_prev(struct player *);
|
||||||
|
|
|
@ -135,18 +135,15 @@ player_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct player *
|
struct player *
|
||||||
player_new(int s, struct sockaddr_in *sin)
|
player_new(int s)
|
||||||
{
|
{
|
||||||
struct player *lp;
|
struct player *lp;
|
||||||
#ifdef RESOLVE_IPADDRESS
|
|
||||||
struct hostent *hostp;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
lp = malloc(sizeof(struct player));
|
lp = malloc(sizeof(struct player));
|
||||||
if (!lp)
|
if (!lp)
|
||||||
return NULL;
|
return NULL;
|
||||||
memset(lp, 0, sizeof(struct player));
|
memset(lp, 0, sizeof(struct player));
|
||||||
if (sin) {
|
if (s >= 0) {
|
||||||
/* real player, not dummy created by update and market update */
|
/* real player, not dummy created by update and market update */
|
||||||
lp->iop = io_open(s,
|
lp->iop = io_open(s,
|
||||||
IO_READ | IO_WRITE | IO_NBLOCK,
|
IO_READ | IO_WRITE | IO_NBLOCK,
|
||||||
|
@ -156,13 +153,6 @@ player_new(int s, struct sockaddr_in *sin)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
emp_insque(&lp->queue, &Players);
|
emp_insque(&lp->queue, &Players);
|
||||||
strcpy(lp->hostaddr, inet_ntoa(sin->sin_addr));
|
|
||||||
#ifdef RESOLVE_IPADDRESS
|
|
||||||
if (NULL !=
|
|
||||||
(hostp = gethostbyaddr(&sin->sin_addr, sizeof(sin->sin_addr),
|
|
||||||
AF_INET)))
|
|
||||||
strcpy(lp->hostname, hostp->h_name);
|
|
||||||
#endif /* RESOLVE_IPADDRESS */
|
|
||||||
lp->cnum = 255;
|
lp->cnum = 255;
|
||||||
lp->curid = -1;
|
lp->curid = -1;
|
||||||
time(&lp->curup);
|
time(&lp->curup);
|
||||||
|
@ -258,6 +248,9 @@ player_accept(void *unused)
|
||||||
int set = 1;
|
int set = 1;
|
||||||
int stacksize;
|
int stacksize;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
#ifdef RESOLVE_IPADDRESS
|
||||||
|
struct hostent *hostp;
|
||||||
|
#endif
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
empth_select(s, EMPTH_FD_READ);
|
empth_select(s, EMPTH_FD_READ);
|
||||||
|
@ -268,12 +261,19 @@ player_accept(void *unused)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
(void)setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE, &set, sizeof(set));
|
(void)setsockopt(ns, SOL_SOCKET, SO_KEEPALIVE, &set, sizeof(set));
|
||||||
np = player_new(ns, &sin);
|
np = player_new(ns);
|
||||||
if (!np) {
|
if (!np) {
|
||||||
logerror("can't create player for fd %d", ns);
|
logerror("can't create player for fd %d", ns);
|
||||||
close(ns);
|
close(ns);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
strcpy(np->hostaddr, inet_ntoa(sin.sin_addr));
|
||||||
|
#ifdef RESOLVE_IPADDRESS
|
||||||
|
if (NULL !=
|
||||||
|
(hostp = gethostbyaddr(&sin.sin_addr, sizeof(sin.sin_addr),
|
||||||
|
AF_INET)))
|
||||||
|
strcpy(np->hostname, hostp->h_name);
|
||||||
|
#endif /* RESOLVE_IPADDRESS */
|
||||||
/* XXX may not be big enough */
|
/* XXX may not be big enough */
|
||||||
stacksize = 100000
|
stacksize = 100000
|
||||||
/* budget */ + max(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7,
|
/* budget */ + max(WORLD_X * WORLD_Y / 2 * sizeof(int) * 7,
|
||||||
|
|
|
@ -72,7 +72,7 @@ market_update(void *unused)
|
||||||
while (1) {
|
while (1) {
|
||||||
time(&now);
|
time(&now);
|
||||||
/* logerror("Checking the world markets at %s", ctime(&now));*/
|
/* logerror("Checking the world markets at %s", ctime(&now));*/
|
||||||
dp = player_new(0, 0);
|
dp = player_new(-1);
|
||||||
if (dp) {
|
if (dp) {
|
||||||
empth_create(PP_UPDATE, check_all_markets, (50 * 1024), 0,
|
empth_create(PP_UPDATE, check_all_markets, (50 * 1024), 0,
|
||||||
"MarketCheck", "Checks the world markets", dp);
|
"MarketCheck", "Checks the world markets", dp);
|
||||||
|
|
|
@ -147,7 +147,7 @@ update_wait(void *unused)
|
||||||
* we rely on the fact that update's priority is the highest
|
* we rely on the fact that update's priority is the highest
|
||||||
* in the land so it can finish before it yields.
|
* in the land so it can finish before it yields.
|
||||||
*/
|
*/
|
||||||
dp = player_new(0, 0);
|
dp = player_new(-1);
|
||||||
if (!dp) {
|
if (!dp) {
|
||||||
logerror("can't create dummy player for update");
|
logerror("can't create dummy player for update");
|
||||||
update_pending = 0;
|
update_pending = 0;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue