Commit 194c0723 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add a VTCP_open() function to replace VSS_open().

libc should have had a function like this at least 25 years ago :-/
parent a4fdf38a
......@@ -53,6 +53,8 @@ void VTCP_name(const struct suckaddr *addr, char *abuf, unsigned alen,
char *pbuf, unsigned plen);
int VTCP_connected(int s);
int VTCP_connect(const struct suckaddr *name, int msec);
int VTCP_open(const char *addr, const char *def_port, double timeout,
const char **err);
void VTCP_close(int *s);
void VTCP_set_read_timeout(int s, double seconds);
#endif
......@@ -50,8 +50,10 @@
#include <string.h>
#include <unistd.h>
#include "vdef.h"
#include "vas.h"
#include "vsa.h"
#include "vss.h"
#include "vtcp.h"
/*--------------------------------------------------------------------*/
......@@ -325,6 +327,37 @@ VTCP_set_read_timeout(int s, double seconds)
#endif
}
/*--------------------------------------------------------------------
*/
static int __match_proto__(vss_resolved_f)
vtcp_open_callback(void *priv, const struct suckaddr *sa)
{
double *p = priv;
return (VTCP_connect(sa, (int)floor(*p * 1e3)));
}
int
VTCP_open(const char *addr, const char *def_port, double timeout,
const char **errp)
{
int error;
const char *err;
if (errp != NULL)
*errp = NULL;
assert(timeout >= 0);
error = VSS_resolver(addr, def_port, vtcp_open_callback,
&timeout, &err);
if (err != NULL) {
if (errp != NULL)
*errp = err;
return (-1);
}
return (error);
}
/*--------------------------------------------------------------------
* Set or reset SO_LINGER flag
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment