socket/tcp/udp errors more verbose (strerror)

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@3872 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Lance 2011-07-14 09:18:04 +00:00
parent 7fa677ccf5
commit 4943723a8b
3 changed files with 86 additions and 83 deletions

View file

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "qtv.h"
#include <string.h>
#define curtime Sys_Milliseconds()
@ -43,7 +44,7 @@ void NET_SendPacket(cluster_t *cluster, SOCKET sock, int length, void *data, net
if (er == EWOULDBLOCK || er == EAGAIN)
return;
Sys_Printf(cluster, "udp send error %i\n", er);
Sys_Printf(cluster, "udp send error %i (%s)\n", er, strerror(er));
}
}
@ -160,7 +161,7 @@ void Netchan_OutOfBand (cluster_t *cluster, SOCKET sock, netadr_t adr, int lengt
// write the packet header
InitNetMsg (&send, send_buf, sizeof(send_buf));
WriteLong (&send, -1); // -1 sequence means out of band
WriteData (&send, data, length);
@ -180,7 +181,7 @@ void Netchan_OutOfBandPrint (cluster_t *cluster, SOCKET sock[], netadr_t adr, ch
{
va_list argptr;
char string[8192];
va_start (argptr, format);
#ifdef _WIN32
_vsnprintf (string, sizeof(string) - 1, format, argptr);
@ -215,7 +216,7 @@ called to open a channel to a remote system
void Netchan_Setup (SOCKET sock, netchan_t *chan, netadr_t adr, int qport, qboolean isclient)
{
memset (chan, 0, sizeof(*chan));
chan->sock = sock;
memcpy(&chan->remote_address, &adr, sizeof(netadr_t));
chan->qport = qport;
@ -226,7 +227,7 @@ void Netchan_Setup (SOCKET sock, netchan_t *chan, netadr_t adr, int qport, qbool
InitNetMsg(&chan->message, chan->message_buf, sizeof(chan->message_buf));
chan->message.allowoverflow = true;
chan->rate = 1000.0f/2500;
}
@ -256,7 +257,7 @@ qboolean Netchan_CanPacket (netchan_t *chan)
===============
Netchan_CanReliable
Returns true if the bandwidth choke isn't
Returns true if the bandwidth choke isn't
================
*/
qboolean Netchan_CanReliable (netchan_t *chan)
@ -404,7 +405,7 @@ void Netchan_Transmit (cluster_t *cluster, netchan_t *chan, int length, const vo
WriteData (&send, chan->reliable_buf, chan->reliable_length);
chan->last_reliable_sequence = chan->outgoing_sequence;
}
// add the unreliable part if space is available
if (send.maxsize - send.cursize >= length)
WriteData (&send, data, length);
@ -553,7 +554,7 @@ qboolean Netchan_Process (netchan_t *chan, netmsg_t *msg)
unsigned sequence, sequence_ack;
unsigned reliable_ack, reliable_message;
// get sequence numbers
// get sequence numbers
msg->readpos = 0;
sequence = ReadLong (msg);
sequence_ack = ReadLong (msg);
@ -565,8 +566,8 @@ qboolean Netchan_Process (netchan_t *chan, netmsg_t *msg)
reliable_message = sequence >> 31;
reliable_ack = sequence_ack >> 31;
sequence &= ~(1<<31);
sequence_ack &= ~(1<<31);
sequence &= ~(1<<31);
sequence_ack &= ~(1<<31);
/* if (showpackets.value)
Com_Printf ("<-- s=%i(%i) a=%i(%i) %i\n"
@ -614,9 +615,9 @@ qboolean Netchan_Process (netchan_t *chan, netmsg_t *msg)
//
if (reliable_ack == (unsigned)chan->reliable_sequence)
chan->reliable_length = 0; // it has been received
//
// if this message contains a reliable message, bump incoming_reliable_sequence
// if this message contains a reliable message, bump incoming_reliable_sequence
//
chan->incoming_sequence = sequence;
chan->incoming_acknowledged = sequence_ack;
@ -631,7 +632,7 @@ qboolean Netchan_Process (netchan_t *chan, netmsg_t *msg)
// chan->frame_latency = chan->frame_latency*OLD_AVG
// + (chan->outgoing_sequence-sequence_ack)*(1.0-OLD_AVG);
// chan->frame_rate = chan->frame_rate*OLD_AVG
// + (curtime - chan->last_received)*(1.0-OLD_AVG);
// + (curtime - chan->last_received)*(1.0-OLD_AVG);
// chan->good_count += 1;
chan->last_received = curtime;

View file

@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "qtv.h"
#include <string.h>
#include "bsd_string.h"
@ -200,7 +201,7 @@ SOCKET QW_InitUDPSocket(int port, qboolean ipv6)
if( bind (sock, (void *)address, addrlen) == -1)
{
printf("socket bind error %i\n", qerrno);
printf("socket bind error %i (%s)\n", qerrno, strerror(qerrno));
closesocket(sock);
return INVALID_SOCKET;
}
@ -439,7 +440,7 @@ void SendNQSpawnInfoToViewer(cluster_t *cluster, viewer_t *viewer, netmsg_t *msg
int SendCurrentUserinfos(sv_t *tv, int cursize, netmsg_t *msg, int i, int thisplayer)
{
char name[MAX_QPATH];
if (i < 0)
return i;
if (i >= MAX_CLIENTS)
@ -677,7 +678,7 @@ void QW_StreamStuffcmd(cluster_t *cluster, sv_t *server, char *fmt, ...)
InitNetMsg(&msg, buf, sizeof(buf));
WriteByte(&msg, svc_stufftext);
WriteString(&msg, cmd);
for (v = cluster->viewers; v; v = v->next)
{
@ -798,14 +799,14 @@ void ParseUserInfo(cluster_t *cluster, viewer_t *viewer)
{
if (*viewer->name)
{
snprintf(buf, sizeof(buf), "%cQTV%c%s changed name to %cQTV%c%s\n",
snprintf(buf, sizeof(buf), "%cQTV%c%s changed name to %cQTV%c%s\n",
91+128, 93+128, viewer->name,
91+128, 93+128, temp
);
}
else
{
snprintf(buf, sizeof(buf), "%cQTV%c%s joins the stream\n",
snprintf(buf, sizeof(buf), "%cQTV%c%s joins the stream\n",
91+128, 93+128, temp
);
@ -1161,7 +1162,7 @@ void QTV_Status(cluster_t *cluster, netadr_t *from)
// sprintf(elem, " (%s)", sv->serveraddress);
// WriteString2(&msg, elem);
}
WriteString2(&msg, "\n");
}
@ -1176,7 +1177,7 @@ void QTV_StatusResponse(cluster_t *cluster, char *msg, netadr_t *from)
sv_t *sv;
char *eol;
for (sv = cluster->servers; sv; sv = sv->next)
{
/*ignore connected streams*/
@ -1606,21 +1607,21 @@ void SendNQClientData(sv_t *tv, viewer_t *v, netmsg_t *msg)
pl = &tv->map.players[v->trackplayer];
bits = 0;
if (!pl->dead)
bits |= SU_VIEWHEIGHT;
if (0)
bits |= SU_IDEALPITCH;
bits |= SU_ITEMS;
if ( 0)
bits |= SU_ONGROUND;
if ( 0 )
bits |= SU_INWATER;
for (i=0 ; i<3 ; i++)
{
if (0)
@ -1628,7 +1629,7 @@ void SendNQClientData(sv_t *tv, viewer_t *v, netmsg_t *msg)
if (0)
bits |= (SU_VELOCITY1<<i);
}
if (pl->current.weaponframe)
bits |= SU_WEAPONFRAME;
@ -1666,7 +1667,7 @@ void SendNQClientData(sv_t *tv, viewer_t *v, netmsg_t *msg)
WriteByte (msg, pl->stats[STAT_ARMOR]);
if (bits & SU_WEAPON)
WriteByte (msg, pl->stats[STAT_WEAPON]);
WriteShort (msg, pl->stats[STAT_HEALTH]);
WriteByte (msg, pl->stats[STAT_AMMO]);
WriteByte (msg, pl->stats[STAT_SHELLS]);
@ -1718,7 +1719,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if (tv)
{
if (v->trackplayer >= 0)
{
WriteByte(msg, svc_nqsetview);
@ -1748,7 +1749,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if (e+1 >= 256)
bits |= UNQ_LONGENTITY;
if (bits >= 256)
bits |= UNQ_MOREBITS;
WriteByte (msg,bits | UNQ_SIGNAL);
@ -1770,7 +1771,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if (bits & UNQ_EFFECTS)
WriteByte (msg, 0);
if (bits & UNQ_ORIGIN1)
WriteShort (msg, v->origin[0]*8);
WriteShort (msg, v->origin[0]*8);
if (bits & UNQ_ANGLE1)
WriteByte(msg, -(v->ucmds[2].angles[0]>>8));
if (bits & UNQ_ORIGIN2)
@ -1791,10 +1792,10 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
continue;
pl->current.modelindex = 8;
// send an update
bits = 0;
for (i=0 ; i<3 ; i++)
{
org[i] = (lerp)*pl->current.origin[i] + (1-lerp)*pl->old.origin[i];
@ -1803,34 +1804,34 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if ( pl->current.angles[0]>>8 != ent->baseline.angles[0] )
bits |= UNQ_ANGLE1;
if ( pl->current.angles[1]>>8 != ent->baseline.angles[1] )
bits |= UNQ_ANGLE2;
if ( pl->current.angles[2]>>8 != ent->baseline.angles[2] )
bits |= UNQ_ANGLE3;
// if (pl->v.movetype == MOVETYPE_STEP)
// bits |= UNQ_NOLERP; // don't mess up the step animation
if (ent->baseline.colormap != e+1 || ent->baseline.colormap > 15)
bits |= UNQ_COLORMAP;
if (ent->baseline.skinnum != pl->current.skinnum)
bits |= UNQ_SKIN;
if (ent->baseline.frame != pl->current.frame)
bits |= UNQ_FRAME;
if (ent->baseline.effects != pl->current.effects)
bits |= UNQ_EFFECTS;
if (ent->baseline.modelindex != pl->current.modelindex)
bits |= UNQ_MODEL;
if (e+1 >= 256)
bits |= UNQ_LONGENTITY;
if (bits >= 256)
bits |= UNQ_MOREBITS;
@ -1838,7 +1839,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
// write the message
//
WriteByte (msg,bits | UNQ_SIGNAL);
if (bits & UNQ_MOREBITS)
WriteByte (msg, bits>>8);
if (bits & UNQ_LONGENTITY)
@ -1857,7 +1858,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if (bits & UNQ_EFFECTS)
WriteByte (msg, pl->current.effects);
if (bits & UNQ_ORIGIN1)
WriteShort (msg, org[0]);
WriteShort (msg, org[0]);
if (bits & UNQ_ANGLE1)
WriteByte(msg, -(pl->current.angles[0]>>8));
if (bits & UNQ_ORIGIN2)
@ -1870,7 +1871,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
WriteByte(msg, pl->current.angles[2]>>8);
}
{
int newindex = 0;
entity_state_t *newstate;
@ -1908,34 +1909,34 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if (newstate->angles[0] != ent->baseline.angles[0])
bits |= UNQ_ANGLE1;
if (newstate->angles[1] != ent->baseline.angles[1])
bits |= UNQ_ANGLE2;
if (newstate->angles[2] != ent->baseline.angles[2])
bits |= UNQ_ANGLE3;
// if (ent->v.movetype == MOVETYPE_STEP)
// bits |= UNQ_NOLERP; // don't mess up the step animation
if (newstate->colormap != ent->baseline.colormap || ent->baseline.colormap > 15)
bits |= UNQ_COLORMAP;
if (newstate->skinnum != ent->baseline.skinnum)
bits |= UNQ_SKIN;
if (newstate->frame != ent->baseline.frame)
bits |= UNQ_FRAME;
if (newstate->effects != ent->baseline.effects)
bits |= UNQ_EFFECTS;
if (newstate->modelindex != ent->baseline.modelindex)
bits |= UNQ_MODEL;
if (newnum >= 256)
bits |= UNQ_LONGENTITY;
if (bits >= 256)
bits |= UNQ_MOREBITS;
@ -1943,7 +1944,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
// write the message
//
WriteByte (msg,bits | UNQ_SIGNAL);
if (bits & UNQ_MOREBITS)
WriteByte (msg, bits>>8);
if (bits & UNQ_LONGENTITY)
@ -1962,7 +1963,7 @@ void SendNQPlayerStates(cluster_t *cluster, sv_t *tv, viewer_t *v, netmsg_t *msg
if (bits & UNQ_EFFECTS)
WriteByte (msg, newstate->effects);
if (bits & UNQ_ORIGIN1)
WriteShort (msg, newstate->origin[0]);
WriteShort (msg, newstate->origin[0]);
if (bits & UNQ_ANGLE1)
WriteByte(msg, newstate->angles[0]);
if (bits & UNQ_ORIGIN2)
@ -2224,7 +2225,7 @@ void SendPlayerStates(sv_t *tv, viewer_t *v, netmsg_t *msg)
if (oldindex < frompacket->numents)
{
oldnum = frompacket->entnums[oldindex];
while(oldnum < newnum)
{
oldindex++;
@ -2609,7 +2610,7 @@ guimenu:
shownheader = false;
QW_StuffcmdToViewer(v,
QW_StuffcmdToViewer(v,
"alias menucallback\n"
"{\n"
@ -2670,7 +2671,7 @@ guimenu:
}
if (!shownheader)
QW_StuffcmdToViewer(v, "menutext 72 %i \"There are no active games\"\n", y);
}
else if (!strcmp(command, "demos"))
@ -2696,7 +2697,7 @@ guidemos:
start = atoi(args); //FIXME
QW_SetMenu(v, MENU_NONE);
QW_StuffcmdToViewer(v,
QW_StuffcmdToViewer(v,
"alias menucallback\n"
"{\n"
@ -2765,7 +2766,7 @@ tuidemos:
guiadmin:
if (!*cluster->adminpassword)
{
QW_StuffcmdToViewer(v,
QW_StuffcmdToViewer(v,
"alias menucallback\n"
"{\n"
@ -2785,7 +2786,7 @@ guiadmin:
QW_SetMenu(v, MENU_ADMIN);
else
{
QW_StuffcmdToViewer(v,
QW_StuffcmdToViewer(v,
"alias menucallback\n"
"{\n"
@ -2845,7 +2846,7 @@ tuiadmin:
if (!strcmp(command, "join") || !strcmp(command, "connect"))
isjoin = true;
snprintf(buf, sizeof(buf), "udp:%s", args);
qtv = QTV_NewServerConnection(cluster, 0, buf, "", false, AD_WHENEMPTY, !isjoin, false);
if (qtv)
@ -2881,7 +2882,7 @@ tuiadmin:
else if (!strcmp(command, "qtvinfo"))
{
char buf[256];
snprintf(buf, sizeof(buf), "[QuakeTV] %s\n", qtv->serveraddress);
// Print a short line with info about the server
QW_PrintfToViewer(v, buf);
@ -3129,7 +3130,7 @@ void QTV_Say(cluster_t *cluster, sv_t *qtv, viewer_t *v, char *message, qboolean
QW_PrintfToViewer(v, "Opened demo file \"%s\".\n", message);
}
}
else if (!strcmp(v->expectcommand, "adddemo"))
{
snprintf(buf, sizeof(buf), "file:%s", message);
@ -3149,7 +3150,7 @@ void QTV_Say(cluster_t *cluster, sv_t *qtv, viewer_t *v, char *message, qboolean
newp = atoi(message);
if (newp)
{
news = Net_TCPListen(newp, true);
@ -3547,7 +3548,7 @@ void ParseNQC(cluster_t *cluster, sv_t *qtv, viewer_t *v, netmsg_t *m)
if(v->server)
{
int t;
for (t = v->trackplayer+1; t < MAX_CLIENTS; t++)
{
if (v->server->map.players[t].active)
@ -3581,7 +3582,7 @@ void ParseNQC(cluster_t *cluster, sv_t *qtv, viewer_t *v, netmsg_t *m)
{
if (!v->server && !v->menunum)
QW_SetMenu(v, MENU_DEFAULT);
if(v->server)
{
int t;
@ -3821,7 +3822,7 @@ void ParseQWC(cluster_t *cluster, sv_t *qtv, viewer_t *v, netmsg_t *m)
oldmenu = v->menunum;
QW_SetMenu(v, MENU_NONE);
QW_SetMenu(v, oldmenu);
com = v->commentator;
v->commentator = NULL;

View file

@ -53,6 +53,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "qtv.h"
#include <string.h>
#include "bsd_string.h"
@ -260,7 +261,7 @@ SOCKET Net_TCPListen(int port, qboolean ipv6)
if( bind (sock, address, addrsize) == -1)
{
printf("socket bind error %i\n", qerrno);
printf("socket bind error %i (%s)\n", qerrno, strerror(qerrno));
closesocket(sock);
return INVALID_SOCKET;
}
@ -648,10 +649,10 @@ qboolean Net_ConnectToServer(sv_t *qtv)
case SRC_UDP:
qtv->usequakeworldprotocols = true;
return Net_ConnectToUDPServer(qtv, ip);
case SRC_TCP:
return Net_ConnectToTCPServer(qtv, ip);
default:
Sys_Printf(qtv->cluster, "Unknown source type %s\n", ip);
return false;
@ -692,7 +693,7 @@ qboolean Net_WriteUpstream(sv_t *qtv)
err = qerrno;
if (qerrno)
{
Sys_Printf(qtv->cluster, "Stream %i: Error: source socket error %i\n", qtv->streamid, qerrno);
Sys_Printf(qtv->cluster, "Stream %i: Error: source socket error %i (%s)\n", qtv->streamid, qerrno, strerror(qerrno));
strcpy(qtv->status, "Network error\n");
}
else
@ -731,7 +732,7 @@ int SV_SayToUpstream(sv_t *qtv, char *message)
#ifndef _MSC_VER
#warning This is incomplete!
#endif
//Sys_Printf(qtv->cluster, "not forwarding say\n");
//Sys_Printf(qtv->cluster, "not forwarding say\n");
return 0;
}
@ -802,7 +803,7 @@ int SV_EarlyParse(sv_t *qtv, unsigned char *buffer, int remaining)
{
ParseMessage(qtv, buffer+lengthofs+4, length - (lengthofs+4), buffer[1], 0xffffffff);
}
remaining -= length;
available += length;
buffer += length;
@ -879,7 +880,7 @@ qboolean Net_ReadStream(sv_t *qtv)
if (qtv->sourcefile)
Sys_Printf(qtv->cluster, "Stream %i: Error: End of file\n", qtv->streamid);
else if (read)
Sys_Printf(qtv->cluster, "Stream %i: Error: source socket error %i\n", qtv->streamid, qerrno);
Sys_Printf(qtv->cluster, "Stream %i: Error: source socket error %i (%s)\n", qtv->streamid, qerrno, strerror(qerrno));
else
Sys_Printf(qtv->cluster, "Stream %i: Error: server %s disconnected\n", qtv->streamid, qtv->server);
if (qtv->sourcesock != INVALID_SOCKET)
@ -1168,7 +1169,7 @@ void QTV_Cleanup(sv_t *qtv, qboolean leaveadmins)
oproxy_t *old;
cluster = qtv->cluster;
//set connected viewers to a different stream
if (cluster->viewserver == qtv)
cluster->viewserver = NULL;
@ -1455,7 +1456,7 @@ void QTV_ParseQWStream(sv_t *qtv)
}
#ifdef COMMENTARY
#include <speex/speex.h>
#include <speex/speex.h>
#endif
void QTV_CollectCommentry(sv_t *qtv)
@ -1492,8 +1493,8 @@ void QTV_CollectCommentry(sv_t *qtv)
/* if (usespeex)
{
SpeexBits bits;
void *enc_state;
SpeexBits bits;
void *enc_state;
int frame_size;
@ -1504,22 +1505,22 @@ void QTV_CollectCommentry(sv_t *qtv)
speex_bits_init(&bits);
enc_state = speex_encoder_init(&speex_nb_mode);
enc_state = speex_encoder_init(&speex_nb_mode);
speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);
speex_encoder_ctl(enc_state,SPEEX_GET_FRAME_SIZE,&frame_size);
speex_bits_reset(&bits);
speex_encode_int(enc_state, (spx_int16_t*)pcmdata, &bits);
samps = speex_bits_write(&bits, buffer+6, sizeof(buffer)-6);
samps = speex_bits_write(&bits, buffer+6, sizeof(buffer)-6);
speex_bits_destroy(&bits);
speex_encoder_destroy(enc_state);
speex_encoder_destroy(enc_state);
}
else*/