• R/O
  • SSH
  • HTTPS

svardos: Commit


Commit MetaInfo

Revision333 (tree)
Time2021-05-14 19:25:27
Authormateuszviste

Log Message

simplified libnet + avoiding on screen garbage during download

Change Summary

Incremental Difference

--- pkgnet/net.c (revision 332)
+++ pkgnet/net.c (revision 333)
@@ -14,6 +14,12 @@
1414 #include "net.h" /* include self for control */
1515
1616
17+struct net_tcpsocket {
18+ tcp_Socket *sock;
19+ tcp_Socket _sock; /* watt32 socket */
20+};
21+
22+
1723 int net_dnsresolve(char *ip, const char *name) {
1824 unsigned long ipnum;
1925 ipnum = resolve(name); /* I could use WatTCP's lookup_host() here to do all
@@ -47,13 +53,9 @@
4753 ipaddr = _inet_addr(ipstr);
4854 if (ipaddr == 0) return(NULL);
4955
50- resultsock = calloc(sizeof(struct net_tcpsocket) + sizeof(tcp_Socket), 1);
56+ resultsock = calloc(sizeof(struct net_tcpsocket), 1);
5157 if (resultsock == NULL) return(NULL);
52- resultsock->sock = resultsock->buffer;
53- if (resultsock->sock == NULL) {
54- free(resultsock);
55- return(NULL);
56- }
58+ resultsock->sock = &(resultsock->_sock);
5759
5860 /* explicitely set user-managed buffer to none (watt32 will use its own internal buffer) */
5961 sock_setbuf(resultsock->sock, NULL, 0);
@@ -99,12 +101,6 @@
99101 /* I could use sock_close() and sock_wait_closed() if I'd want to be
100102 * friendly, but it's much easier on the tcp stack to send a single RST and
101103 * forget about the connection (esp. if the peer is misbehaving) */
102- net_abort(socket);
103-}
104-
105-
106-/* Close the 'sock' socket immediately (to be used when the peer is behaving wrongly) - this is much faster than net_close(). */
107-void net_abort(struct net_tcpsocket *socket) {
108104 sock_abort(socket->sock);
109105 free(socket);
110106 }
--- pkgnet/net.h (revision 332)
+++ pkgnet/net.h (revision 333)
@@ -7,11 +7,7 @@
77 #ifndef libtcp_hdr
88 #define libtcp_hdr
99
10-struct net_tcpsocket {
11- int s; /* used by platforms with BSD-style sockets */
12- void *sock; /* used by other exotic things (like Watt-32) */
13- char buffer[1];
14-};
10+struct net_tcpsocket; /* opaque struct, exact implementation in net.c */
1511
1612 /* resolves name and fills resovled addr into ip. returns 0 on success. */
1713 int net_dnsresolve(char *ip, const char *name);
@@ -41,9 +37,6 @@
4137 /* Close the 'sock' socket. */
4238 void net_close(struct net_tcpsocket *socket);
4339
44-/* Close the 'sock' socket immediately (to be used when the peer is behaving wrongly) - this is much faster than net_close(). */
45-void net_abort(struct net_tcpsocket *socket);
46-
4740 /* Returns an info string about the networking engine being used */
4841 const char *net_engine(void);
4942
--- pkgnet/pkgnet.c (revision 332)
+++ pkgnet/pkgnet.c (revision 333)
@@ -208,7 +208,7 @@
208208 /* update progress once a sec */
209209 if (lastprogressoutput != lastactivity) {
210210 lastprogressoutput = lastactivity;
211- printf("%ld KiB (%ld KiB/s)\r", flen >> 10, (flen >> 10) - (lastflen >> 10));
211+ 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 */
212212 lastflen = flen;
213213 fflush(stdout); /* avoid console buffering */
214214 }
@@ -229,7 +229,7 @@
229229 return(flen);
230230
231231 SHITQUIT:
232- net_abort(sock);
232+ net_close(sock);
233233 return(-1);
234234 }
235235
Show on old repository browser