//pkgnet/net.c |
---|
14,6 → 14,12 |
#include "net.h" /* include self for control */ |
struct net_tcpsocket { |
tcp_Socket *sock; |
tcp_Socket _sock; /* watt32 socket */ |
}; |
int net_dnsresolve(char *ip, const char *name) { |
unsigned long ipnum; |
ipnum = resolve(name); /* I could use WatTCP's lookup_host() here to do all |
47,13 → 53,9 |
ipaddr = _inet_addr(ipstr); |
if (ipaddr == 0) return(NULL); |
resultsock = calloc(sizeof(struct net_tcpsocket) + sizeof(tcp_Socket), 1); |
resultsock = calloc(sizeof(struct net_tcpsocket), 1); |
if (resultsock == NULL) return(NULL); |
resultsock->sock = resultsock->buffer; |
if (resultsock->sock == NULL) { |
free(resultsock); |
return(NULL); |
} |
resultsock->sock = &(resultsock->_sock); |
/* explicitely set user-managed buffer to none (watt32 will use its own internal buffer) */ |
sock_setbuf(resultsock->sock, NULL, 0); |
99,12 → 101,6 |
/* I could use sock_close() and sock_wait_closed() if I'd want to be |
* friendly, but it's much easier on the tcp stack to send a single RST and |
* forget about the connection (esp. if the peer is misbehaving) */ |
net_abort(socket); |
} |
/* Close the 'sock' socket immediately (to be used when the peer is behaving wrongly) - this is much faster than net_close(). */ |
void net_abort(struct net_tcpsocket *socket) { |
sock_abort(socket->sock); |
free(socket); |
} |
//pkgnet/net.h |
---|
7,11 → 7,7 |
#ifndef libtcp_hdr |
#define libtcp_hdr |
struct net_tcpsocket { |
int s; /* used by platforms with BSD-style sockets */ |
void *sock; /* used by other exotic things (like Watt-32) */ |
char buffer[1]; |
}; |
struct net_tcpsocket; /* opaque struct, exact implementation in net.c */ |
/* resolves name and fills resovled addr into ip. returns 0 on success. */ |
int net_dnsresolve(char *ip, const char *name); |
41,9 → 37,6 |
/* Close the 'sock' socket. */ |
void net_close(struct net_tcpsocket *socket); |
/* Close the 'sock' socket immediately (to be used when the peer is behaving wrongly) - this is much faster than net_close(). */ |
void net_abort(struct net_tcpsocket *socket); |
/* Returns an info string about the networking engine being used */ |
const char *net_engine(void); |
//pkgnet/pkgnet.c |
---|
208,7 → 208,7 |
/* update progress once a sec */ |
if (lastprogressoutput != lastactivity) { |
lastprogressoutput = lastactivity; |
printf("%ld KiB (%ld KiB/s)\r", flen >> 10, (flen >> 10) - (lastflen >> 10)); |
printf("%ld KiB (%ld KiB/s) \r", flen >> 10, (flen >> 10) - (lastflen >> 10)); /* trailing spaces are meant to avoid leaving garbage on screen if speed goes from, say, 1000 KiB/s to 9 KiB/s */ |
lastflen = flen; |
fflush(stdout); /* avoid console buffering */ |
} |
229,7 → 229,7 |
return(flen); |
SHITQUIT: |
net_abort(sock); |
net_close(sock); |
return(-1); |
} |