Go to the documentation of this file.
93 if (sl->
len+size >
sizeof(sl->
buf)) {
189 assert(len <= 65535);
204 size =
sizeof(sl->
buf)-sl->
len;
206 va_start(arg, format);
207 n = vsnprintf((
char *)sl->
buf+sl->
len, size, format, arg);
210 if (n <= -1 || (
size_t)n >= size) {
213 sl->
len += (size_t)n;
244 return sizeof(sl->
buf)-sl->
len;
279 stat = recv(fd, sl->
buf+sl->
len, 2-sl->
len, 0);
283 stat = read(fd, sl->
buf+sl->
len, 2-sl->
len);
284 }
while ((stat == -1) && (errno == EINTR));
291 if ((stat == -1) && WSAGetLastError() != WSAEWOULDBLOCK) {
292 if (WSAGetLastError() == WSAECONNRESET)
295 LOG(
llevDebug,
"ReadPacket got error %d, returning -1\n", WSAGetLastError());
300 if (errno == ECONNRESET) {
301 LOG(
llevDebug,
"ReadPacket got error %s, returning -1\n", strerror(errno));
304 if (errno != EAGAIN && errno != EWOULDBLOCK) {
305 LOG(
llevDebug,
"ReadPacket got error %s, returning 0\n", strerror(errno));
323 toread = 2+(sl->
buf[0]<<8)+sl->
buf[1]-sl->
len;
324 if ((toread+(
int)sl->
len) >= len) {
325 LOG(
llevError,
"SockList_ReadPacket: Want to read more bytes than will fit in buffer (%lu>=%lu).\n", (
unsigned long)toread+sl->
len, (
unsigned long)len);
331 stat = recv(fd, sl->
buf+2, 100, 0);
333 stat = read(fd, sl->
buf+2, 100);
342 stat = recv(fd, sl->
buf+sl->
len, toread, 0);
345 stat = read(fd, sl->
buf+sl->
len, toread);
346 }
while ((stat < 0) && (errno == EINTR));
350 if ((stat == -1) && WSAGetLastError() != WSAEWOULDBLOCK) {
351 if (WSAGetLastError() == WSAECONNRESET)
354 LOG(
llevDebug,
"ReadPacket got error %d, returning -1\n", WSAGetLastError());
359 if (errno != EAGAIN && errno != EWOULDBLOCK) {
360 LOG(
llevDebug,
"ReadPacket got error %s, returning 0\n", strerror(errno));
376 LOG(
llevError,
"SockList_ReadPacket: Read more bytes than desired.\n");
379 }
while (toread > 0);
398 LOG(
llevDebug,
"Write_To_Socket called with dead socket\n");
402 const int amt =
send(ns->
fd,
buf, len, 0);
405 if (amt == -1 && WSAGetLastError() != WSAEWOULDBLOCK) {
406 LOG(
llevInfo,
"New socket write failed WTS (%d).\n",
409 if (errno != EWOULDBLOCK) {
417 "Write_To_Socket: write would block; disconnecting. Try "
418 "increasing SOCKETBUFSIZE.\n");
422 }
else if (amt != len) {
423 LOG(
llevError,
"Write_To_Socket: write wrote less than requested; "
424 "disconnecting. Try increasing SOCKETBUFSIZE.\n");
444 sl->
buf[0] = ((sl->
len-2)>>8)&0xFF;
445 sl->
buf[1] = (sl->
len-2)&0xFF;
465 time_t now = time(NULL);
473 LOG(
llevInfo,
"CSSTAT: %.16s tot %d %d %d %ld inc %d %d %d %ld\n",
void SockList_Init(SockList *sl)
void SockList_AddInt64(SockList *sl, uint64_t data)
void SockList_AddChar(SockList *sl, unsigned char data)
void SockList_AddInt(SockList *sl, uint32_t data)
static void Write_To_Socket(socket_struct *ns, const unsigned char *buf, const int len)
int GetInt_String(const unsigned char *data)
void SockList_AddPrintf(SockList *sl, const char *format,...)
void SockList_AddLen8Data(SockList *sl, const void *data, size_t len)
void SockList_NullTerminate(SockList *sl)
void SockList_AddLen16Data(SockList *sl, const void *data, size_t len)
static void SockList_Ensure(const SockList *sl, size_t size)
void Send_With_Handling(socket_struct *ns, SockList *sl)
void fatal(enum fatal_error err)
int count_all_players(void)
void SockList_AddData(SockList *sl, const void *data, size_t len)
char * stringbuffer_finish(StringBuffer *sb)
void SockList_AddShort(SockList *sl, uint16_t data)
short GetShort_String(const unsigned char *data)
void LOG(LogLevel logLevel, const char *format,...)
void write_cs_stats(void)
void SockList_Reset(SockList *sl)
void SockList_ResetRead(SockList *sl)
size_t SockList_Avail(const SockList *sl)
void SockList_Term(SockList *sl)
void SockList_AddString(SockList *sl, const char *data)
void SockList_AddStringBuffer(SockList *sl, StringBuffer *sb)
unsigned char buf[MAXSOCKBUF]
int SockList_ReadPacket(int fd, SockList *sl, int len)