static int ServerScanner_Thread_Init(struct ServerScanner *serverscanner) { serverscanner->netdata = Sys_Net_Init(); if (serverscanner->netdata) { return 1; } return 0; }
void NET_Init(struct qw_connection *qwc) { qwc->netdata = malloc(sizeof(struct NetData)); if (qwc->netdata) { memset(qwc->netdata, 0, sizeof(struct NetData)); qwc->netdata->sysnetdata = Sys_Net_Init(); if (qwc->netdata->sysnetdata == 0) Com_Printf("Failed to initialise networking\n"); } }
static void QTVR_Thread(void *arg) { struct qtvr *qtvr; int r; char buf[128]; struct netaddr serveraddr; struct netaddr addr; struct SysNetData *netdata; struct SysSocket *socket; qtvr = arg; netdata = Sys_Net_Init(); if (netdata == NULL) { Com_Printf("QTVR_Thread: Sys_Net_Init failed.\n"); } else { if (!NET_StringToAdr(netdata, qtvr->server, &serveraddr)) { Com_Printf("QTVR_Thread: Unable to parse/resolve hoststring.\n"); } else { socket = Sys_Net_CreateSocket(netdata, serveraddr.type); if (socket == NULL) { Com_Printf("QTVR_Create: could not create socket.\n"); } else { Sys_Net_Send(netdata, socket, qtvr->request, strlen(qtvr->request), &serveraddr); while (!qtvr->quit) { Sys_Net_Wait(netdata, socket, 50000); if ((r = Sys_Net_Receive(netdata, socket, buf, sizeof(buf) - 1, &addr)) > 0) { buf[r] = 0; Sys_Thread_LockMutex(qtvr->mutex); qtvr->retval = strdup(buf); if (qtvr->retval == NULL) qtvr->status = QTVR_ERROR; else qtvr->status = QTVR_REPLY_RECIEVED; Sys_Thread_UnlockMutex(qtvr->mutex); break; } } Sys_Net_DeleteSocket(netdata, socket); } } Sys_Net_Shutdown(netdata); } if (qtvr->status != QTVR_REPLY_RECIEVED) qtvr->status = QTVR_ERROR; }