• R/O
  • SSH
  • HTTPS

svardos: Commit


Commit MetaInfo

Revision329 (tree)
Time2021-05-14 04:45:29
Authormateuszviste

Log Message

cleaned up a little the net.h api

Change Summary

Incremental Difference

--- pkgnet/net.c (revision 328)
+++ pkgnet/net.c (revision 329)
@@ -68,8 +68,7 @@
6868 }
6969
7070
71-int net_isconnected(struct net_tcpsocket *s, int waitstate) {
72- waitstate = waitstate; /* gcc warning shut */
71+int net_isconnected(struct net_tcpsocket *s) {
7372 if (tcp_tick(s->sock) == 0) return(-1);
7473 if (sock_established(s->sock) == 0) return(0);
7574 return(1);
@@ -78,24 +77,20 @@
7877
7978 /* Sends data on socket 'socket'.
8079 Returns the number of bytes sent on success, and < 0 otherwise */
81-int net_send(struct net_tcpsocket *socket, const char *line, long len) {
82- int res;
80+int net_send(struct net_tcpsocket *socket, const void *line, long len) {
8381 /* call this to let Watt-32 handle its internal stuff */
8482 if (tcp_tick(socket->sock) == 0) return(-1);
8583 /* send bytes */
86- res = sock_write(socket->sock, (void *)line, len);
87- return(res);
84+ return(sock_write(socket->sock, line, len));
8885 }
8986
9087
9188 /* Reads data from socket 'sock' and write it into buffer 'buff', until end of connection. Will fall into error if the amount of data is bigger than 'maxlen' bytes.
9289 Returns the amount of data read (in bytes) on success, or a negative value otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
93-int net_recv(struct net_tcpsocket *socket, char *buff, long maxlen) {
94- int i;
90+int net_recv(struct net_tcpsocket *socket, void *buff, long maxlen) {
9591 /* call this to let WatTCP handle its internal stuff */
9692 if (tcp_tick(socket->sock) == 0) return(-1);
97- i = sock_fastread(socket->sock, (void *)buff, maxlen);
98- return(i);
93+ return(sock_fastread(socket->sock, buff, maxlen));
9994 }
10095
10196
--- pkgnet/net.h (revision 328)
+++ pkgnet/net.h (revision 329)
@@ -27,19 +27,16 @@
2727 /* checks whether or not a socket is connected. returns:
2828 * 0 = not connected,
2929 * 1 = connected
30- * -1 = error
31- *
32- * if waitstate is non-zero, then net_isconnected() may release a few cpu
33- * cycles (useful when net_isconnected() is used within a busy loop). */
34-int net_isconnected(struct net_tcpsocket *s, int waitstate);
30+ * -1 = error */
31+int net_isconnected(struct net_tcpsocket *s);
3532
3633 /* Sends data on socket 'socket'.
3734 Returns the number of bytes sent on success, and <0 otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
38-int net_send(struct net_tcpsocket *socket, const char *line, long len);
35+int net_send(struct net_tcpsocket *socket, const void *line, long len);
3936
4037 /* Reads data from socket 'sock' and write it into buffer 'buff', until end of connection. Will fall into error if the amount of data is bigger than 'maxlen' bytes.
4138 Returns the amount of data read (in bytes) on success, or a negative value otherwise. The error code can be translated into a human error message via libtcp_strerr(). */
42-int net_recv(struct net_tcpsocket *socket, char *buff, long maxlen);
39+int net_recv(struct net_tcpsocket *socket, void *buff, long maxlen);
4340
4441 /* Close the 'sock' socket. */
4542 void net_close(struct net_tcpsocket *socket);
--- pkgnet/pkgnet.c (revision 328)
+++ pkgnet/pkgnet.c (revision 329)
@@ -128,7 +128,7 @@
128128
129129 /* wait for net_connect() to actually connect */
130130 for (;;) {
131- int connstate = net_isconnected(sock, 1);
131+ int connstate = net_isconnected(sock);
132132 if (connstate > 0) break;
133133 if (connstate < 0) {
134134 puts("ERROR: connection error");
@@ -140,7 +140,7 @@
140140 /* socket is connected - send the http request */
141141 snprintf((char *)buffer, sizeof(buffer), "GET %s HTTP/1.1\r\nHOST: " HOSTADDR "\r\nUSER-AGENT: pkgnet\r\nConnection: close\r\n\r\n", url);
142142
143- if (net_send(sock, (char *)buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
143+ if (net_send(sock, buffer, strlen((char *)buffer)) != (int)strlen((char *)buffer)) {
144144 puts("ERROR: failed to send HTTP query to remote server");
145145 goto SHITQUIT;
146146 }
@@ -147,7 +147,7 @@
147147
148148 lastactivity = time(NULL);
149149 for (;;) {
150- int byteread = net_recv(sock, (char *)buffer, sizeof(buffer) - 1); /* -1 because I will append a NULL terminator */
150+ int byteread = net_recv(sock, buffer, sizeof(buffer) - 1); /* -1 because I will append a NULL terminator */
151151
152152 if (byteread < 0) break; /* end of connection */
153153
Show on old repository browser