summaryrefslogtreecommitdiffstats
path: root/lib/libfetch/common.c
diff options
context:
space:
mode:
authordes <des@FreeBSD.org>2000-07-11 23:50:08 +0000
committerdes <des@FreeBSD.org>2000-07-11 23:50:08 +0000
commit848e1688b8b197884a50800324df1f3d1399c2b4 (patch)
treeb3af026834ffe38668a7e4d76045655057e092c7 /lib/libfetch/common.c
parentb7f030c2c0a5af0d5a92f76f2891ad65c40547a0 (diff)
downloadFreeBSD-src-848e1688b8b197884a50800324df1f3d1399c2b4.zip
FreeBSD-src-848e1688b8b197884a50800324df1f3d1399c2b4.tar.gz
Add _fetch_putln()
Diffstat (limited to 'lib/libfetch/common.c')
-rw-r--r--lib/libfetch/common.c34
1 files changed, 29 insertions, 5 deletions
diff --git a/lib/libfetch/common.c b/lib/libfetch/common.c
index 05104fe..e4dbf3a 100644
--- a/lib/libfetch/common.c
+++ b/lib/libfetch/common.c
@@ -31,6 +31,7 @@
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/time.h>
+#include <sys/uio.h>
#include <netinet/in.h>
#include <errno.h>
@@ -58,6 +59,9 @@ static struct fetcherr _netdb_errlist[] = {
{ -1, FETCH_UNKNOWN, "Unknown resolver error" }
};
+/* End-of-Line */
+static char ENDL[2] = "\r\n";
+
/*** Error-reporting functions ***********************************************/
@@ -193,18 +197,17 @@ _fetch_connect(char *host, int port, int af, int verbose)
_fetch_info("connecting to %s:%d", host, port);
/* try to connect */
- sd = -1;
- for (res = res0; res; res = res->ai_next) {
+ for (sd = -1, res = res0; res; res = res->ai_next) {
if ((sd = socket(res->ai_family, res->ai_socktype,
- res->ai_protocol)) < 0)
+ res->ai_protocol)) == -1)
continue;
- if (connect(sd, res->ai_addr, res->ai_addrlen) >= 0)
+ if (connect(sd, res->ai_addr, res->ai_addrlen) != -1)
break;
close(sd);
sd = -1;
}
freeaddrinfo(res0);
- if (sd < 0) {
+ if (sd == -1) {
_fetch_syserr();
return -1;
}
@@ -295,6 +298,27 @@ _fetch_getln(int fd, char **buf, size_t *size, size_t *len)
}
+/*
+ * Write a line of text to a socket w/ timeout
+ * XXX currently does not enforce timeout
+ */
+int
+_fetch_putln(int fd, char *str, size_t len)
+{
+ struct iovec iov[2];
+ ssize_t wlen;
+
+ /* XXX should enforce timeout */
+ iov[0].iov_base = str;
+ iov[0].iov_len = len;
+ iov[1].iov_base = ENDL;
+ iov[1].iov_len = sizeof ENDL;
+ wlen = writev(fd, iov, 2);
+ DEBUG(fprintf(stderr, "\033[1m>>> %s\n\033[m", str));
+ return (wlen != len);
+}
+
+
/*** Directory-related utility functions *************************************/
int
OpenPOWER on IntegriCloud