]> PatchyGit - patchyircd.git/commitdiff
net: use rbuf/rlen/wbuf/wlen names as originally intended
authorEgor <egor@patchysicp.xyz>
Fri, 13 Jun 2025 02:26:20 +0000 (05:26 +0300)
committerEgor <egor@patchysicp.xyz>
Fri, 13 Jun 2025 02:26:20 +0000 (05:26 +0300)
src/admin.cpp
src/common.h
src/irc.cpp
src/main.cpp
src/net.cpp

index 894bd5a..cc2c4f1 100644 (file)
@@ -142,7 +142,7 @@ static int client_index(lua_State *L)
        /* saslusername */
        /* webircpeername */
        /* webirchostname */
-       /* buf/bufLen/wbuf/wbufLen */
+       /* rbuf/rlen/wbuf/wlen */
        integer_getter(cl, umode);
        integer_getter(cl, regstate);
        map_getter(cl, channels, MAPTYPE_CHANNEL);
index 7b18e08..e8e4001 100644 (file)
@@ -57,10 +57,10 @@ struct client_data {
        char   *saslusername;
        char   *webircpeername;
        char   *webirchostname;
-       char   buf[2048];
-       size_t bufLen;
+       char   rbuf[2048];
+       size_t rlen;
        char   wbuf[8192];
-       size_t wbufLen;
+       size_t wlen;
        char   umode;
        char   regstate;
        channelmap channels;
index 2ee5f23..aac2d9a 100644 (file)
@@ -111,9 +111,9 @@ int parsePacket(struct client_data *client) {
        char *args[16] = {0};
        int argc = 0;
        {
-               char *p = client->buf;
+               char *p = client->rbuf;
                { // remove \r
-                       char *end = (char *)memchr(p, '\n', client->bufLen);
+                       char *end = (char *)memchr(p, '\n', client->rlen);
                        if (end > p && end[-1] == '\r')
                                *--end = '\n';
                        if (memchr(p, '\0', end-p)) {
index d579c05..692df41 100644 (file)
@@ -297,46 +297,46 @@ int main(int argc, char *argv[])
                fake->hostname = mystrdup("localhost");
                if (!fake->hostname)
                        abortf("strdup fail (hostname)\n");
-               strcpy_lit(fake->buf, "NICK :root\r\n");
-               fake->bufLen = strlen(fake->buf);
+               strcpy_lit(fake->rbuf, "NICK :root\r\n");
+               fake->rlen = strlen(fake->rbuf);
                parsePacket(fake);
-               strcpy_lit(fake->buf, "USER root 0 * :Patchouli Knowledge\r\n");
-               fake->bufLen = strlen(fake->buf);
+               strcpy_lit(fake->rbuf, "USER root 0 * :Patchouli Knowledge\r\n");
+               fake->rlen = strlen(fake->rbuf);
                parsePacket(fake);
-               while (fgets(fake->buf, sizeof(fake->buf), f)) {
-                       int len = strlen(fake->buf);
-                       if (!len || fake->buf[len-1] != '\n')
+               while (fgets(fake->rbuf, sizeof(fake->rbuf), f)) {
+                       int len = strlen(fake->rbuf);
+                       if (!len || fake->rbuf[len-1] != '\n')
                                break;
                        unsigned long faketime;
-                       if (sscanf(fake->buf, "$%lu", &faketime)) {
+                       if (sscanf(fake->rbuf, "$%lu", &faketime)) {
                                set_time((time_t)faketime);
-                               char *p = strchr(fake->buf, ' ');
+                               char *p = strchr(fake->rbuf, ' ');
                                if (!p)
                                        continue;
-                               len -= ++p - fake->buf;
-                               memmove(fake->buf, p, len);
+                               len -= ++p - fake->rbuf;
+                               memmove(fake->rbuf, p, len);
                        }
-                       if (fake->buf[0] == ':') {
-                               char *sp = strchr(fake->buf, ' ');
-                               char *bang = strchr(fake->buf, '!');
+                       if (fake->rbuf[0] == ':') {
+                               char *sp = strchr(fake->rbuf, ' ');
+                               char *bang = strchr(fake->rbuf, '!');
                                if (sp && bang && bang < sp) {
-                                       int nlen = bang - fake->buf - 1;
-                                       if (memcmp(&fake->buf[1], fake->nick, nlen) != 0) {
+                                       int nlen = bang - fake->rbuf - 1;
+                                       if (memcmp(&fake->rbuf[1], fake->nick, nlen) != 0) {
                                                char *nnick = (char *)malloc(nlen+1);
                                                if (!nnick)
                                                        abortf("malloc fail (fake->nick)\n");
-                                               memcpy(nnick, &fake->buf[1], nlen);
+                                               memcpy(nnick, &fake->rbuf[1], nlen);
                                                nnick[nlen] = '\0';
                                                free(fake->nick);
                                                fake->nick = nnick;
                                        }
                                }
                        }
-                       fake->bufLen = len;
+                       fake->rlen = len;
                        parsePacket(fake);
                }
-               strcpy_lit(fake->buf, "QUIT :bye\r\n");
-               fake->bufLen = strlen(fake->buf);
+               strcpy_lit(fake->rbuf, "QUIT :bye\r\n");
+               fake->rlen = strlen(fake->rbuf);
                parsePacket(fake);
                set_time(0);
                fclose(f);
@@ -389,10 +389,10 @@ int main(int argc, char *argv[])
                        }
                        case SOCKTYPE_DYING: {
                                struct client_data *cl = (struct client_data *)ev.assoc;
-                               if (cl->wbufLen)
+                               if (cl->wlen)
                                        if ((cl->want_read_for_write && isr) || (cl->want_write_for_write && isw))
                                                sendClient(cl, 0, 0);
-                               if (!cl->wbufLen) {
+                               if (!cl->wlen) {
                                        if (!cl->want_read_for_close && !cl->want_write_for_close)
                                                killConnectionPart2(cl);
                                        else if ((cl->want_read_for_close && isr) || (cl->want_write_for_close && isw))
index 02fd14b..a169f9c 100644 (file)
@@ -154,12 +154,11 @@ void recvProc(struct client_data *cl) {
        char *x;
        int packetReturn;
        cl->want_write_for_read = 0;
-       while(1){
-               // I hate you
-               if(cl->bufLen == sizeof(cl->buf)) { killConnection(cl, 0); return; }
+       for (;;) {
+               if(cl->rlen == sizeof(cl->rbuf)) { killConnection(cl, 0); return; }
 #if HAVE_LIBTLS
                if (cl->cctx) {
-                       bytesRead = tls_read(cl->cctx, cl->buf + cl->bufLen, sizeof(cl->buf) - cl->bufLen);
+                       bytesRead = tls_read(cl->cctx, cl->rbuf + cl->rlen, sizeof(cl->rbuf) - cl->rlen);
                        switch (bytesRead) {
                                // Disconnect
                                case 0:
@@ -182,7 +181,7 @@ void recvProc(struct client_data *cl) {
                else
 #endif
                {
-                       bytesRead = recv(cl->fd, cl->buf + cl->bufLen,sizeof(cl->buf) - cl->bufLen, 0);
+                       bytesRead = recv(cl->fd, cl->rbuf + cl->rlen,sizeof(cl->rbuf) - cl->rlen, 0);
                        switch(bytesRead){
                                // Disconnect
                                case 0:
@@ -199,9 +198,9 @@ void recvProc(struct client_data *cl) {
                                        return;
                        }
                }
-               cl->bufLen += bytesRead;
+               cl->rlen += bytesRead;
                while(1){
-                       x = (char *)memchr(cl->buf, '\n', cl->bufLen);
+                       x = (char *)memchr(cl->rbuf, '\n', cl->rlen);
                        if(!x) break;
                        packetReturn = parsePacket(cl);
                        // Client QUIT
@@ -211,8 +210,8 @@ void recvProc(struct client_data *cl) {
                                update_poll_reg(cl);
                                return;
                        }
-                       memmove(cl->buf, x+1, cl->buf + cl->bufLen-(x+1));
-                       cl->bufLen -= x+1 - cl->buf;
+                       memmove(cl->rbuf, x+1, cl->rbuf + cl->rlen-(x+1));
+                       cl->rlen -= x+1 - cl->rbuf;
                }
        }
 }
@@ -267,13 +266,13 @@ void sendClient(struct client_data *cl, const char *buf, size_t len)
 {
        if (cl->write_error)
                return;
-       if (cl->wbufLen + len > sizeof(cl->wbuf)) {
+       if (cl->wlen + len > sizeof(cl->wbuf)) {
                /* Buffer overrun */
                /* FIXME: probably should terminate the connection at this point */
                len = 0;
                /* we don't return here, because we still want to push old data if possible */
        }
-       if (!cl->wbufLen) {
+       if (!cl->wlen) {
                if (len) {
                        int left = sendClientRaw(cl, buf, len);
                        update_poll_reg(cl);
@@ -291,21 +290,21 @@ void sendClient(struct client_data *cl, const char *buf, size_t len)
                                return;
                        }
                        memcpy(cl->wbuf, buf+len-left, left);
-                       cl->wbufLen = left;
+                       cl->wlen = left;
                }
                return;
        }
        if (len) {
-               memcpy(cl->wbuf + cl->wbufLen, buf, len);
-               cl->wbufLen += len;
+               memcpy(cl->wbuf + cl->wlen, buf, len);
+               cl->wlen += len;
        }
-       int left = sendClientRaw(cl, cl->wbuf, cl->wbufLen);
+       int left = sendClientRaw(cl, cl->wbuf, cl->wlen);
        update_poll_reg(cl);
        if (left == -1) {
-               cl->wbufLen = 0;
+               cl->wlen = 0;
                cl->write_error = 1;
                return;
        }
-       memmove(cl->wbuf, cl->wbuf+cl->wbufLen-left, left);
-       cl->wbufLen = left;
+       memmove(cl->wbuf, cl->wbuf+cl->wlen-left, left);
+       cl->wlen = left;
 }