1
0
mirror of https://github.com/DigitalDevices/dddvb.git synced 2023-10-10 13:37:43 +02:00

add sendlen/sendstring

This commit is contained in:
Ralph Metzler 2019-07-08 10:03:17 +02:00
parent f2ca278710
commit 1064f47fd9
2 changed files with 35 additions and 0 deletions

View File

@ -1,4 +1,37 @@
#include "time.h" #include "time.h"
#include <stdint.h>
#include <stdarg.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
int sendlen(int sock, char *buf, int len)
{
int done, todo;
for (todo = len; todo; todo -= done, buf += done)
if ((done = send(sock, buf, todo, 0)) < 0) {
printf("sendlen error\n");
return done;
}
return len;
}
int sendstring(int sock, char *fmt, ...)
{
int len;
uint8_t buf[2048];
va_list args;
va_start(args, fmt);
len = vsnprintf(buf, sizeof(buf), fmt, args);
if (len <= 0 || len >= sizeof(buf))
return 0;
sendlen(sock, buf, len);
va_end(args);
return len;
}
time_t mtime(time_t *t) time_t mtime(time_t *t)
{ {

View File

@ -2,5 +2,7 @@
#define _DDDVB_TOOLS_H_ #define _DDDVB_TOOLS_H_
time_t mtime(time_t *t); time_t mtime(time_t *t);
int sendlen(int sock, char *buf, int len);
int sendstring(int sock, char *fmt, ...);
#endif /* _DDDVB_TOOLS_H_ */ #endif /* _DDDVB_TOOLS_H_ */