Coder Social home page Coder Social logo

Comments (9)

technojoe avatar technojoe commented on May 27, 2024 1

When I am off work, I will need help with that. I have little experience with GIT and no experience with GitHub.

from task-spooler.

justanhduc avatar justanhduc commented on May 27, 2024

Hey @tomaszklim. Thanks for the suggesstion. Do you want to send a PR?

from task-spooler.

technojoe avatar technojoe commented on May 27, 2024

Changed server.c to dynamically allocate memory for client_cs from getrlimit, which removes the hardcoded, arbitrary limit of 1000. [issue #52]

--- task-spooler-main/server.c	2023-11-26 21:13:44.622381307 -0800
+++ task-spooler/server.c	2023-11-26 20:31:51.485209017 -0800
@@ -29,10 +29,6 @@
 
 #include "main.h"
 
-enum {
-    MAXCONN = 1000
-};
-
 enum Break {
     BREAK,
     NOBREAK,
@@ -63,7 +59,7 @@
 };
 
 /* Globals */
-static struct Client_conn client_cs[MAXCONN];
+static struct Client_conn *client_cs;
 static int nconnections;
 static char *path;
 static int max_descriptors;
@@ -131,12 +127,16 @@
 
 static int get_max_descriptors() {
     const int MARGIN = 5; /* stdin, stderr, listen socket, and whatever */
-    int max;
+    int max = 1000; /* initial value used only if getrlimit fails to return a value */
     struct rlimit rlim;
     int res;
     const char *str;
 
-    max = MAXCONN;
+    res = getrlimit(RLIMIT_NOFILE, &rlim);
+    if (res != 0)
+        warning("getrlimit for open files");
+    else
+        max = rlim.rlim_cur - MARGIN;
 
     str = getenv("TS_MAXCONN");
     if (str != NULL) {
@@ -149,17 +149,6 @@
     if (max > FD_SETSIZE)
         max = FD_SETSIZE - MARGIN;
 
-    /* I'd like to use OPEN_MAX or NR_OPEN, but I don't know if any
-     * of them is POSIX compliant */
-
-    res = getrlimit(RLIMIT_NOFILE, &rlim);
-    if (res != 0)
-        warning("getrlimit for open files");
-    else {
-        if (max > rlim.rlim_cur)
-            max = rlim.rlim_cur - MARGIN;
-    }
-
     if (max < 1)
         error("Too few opened descriptors available");
 
@@ -174,6 +163,9 @@
 
     process_type = SERVER;
     max_descriptors = get_max_descriptors();
+    
+    /* allocate dynamic memory for client_cs, thus removing any arbitrary limit */
+    client_cs = malloc(max_descriptors * sizeof(struct Client_conn));
 
     /* Arbitrary limit, that will block the enqueuing, but should allow space
      * for usual ts queries */
@@ -316,6 +308,7 @@
     /* This comes from the parent, in the fork after server_main.
      * This is the last use of path in this process.*/
     free(path);
+    free(client_cs);
     free(logdir);
 #ifndef CPU
     cleanupGpu();

from task-spooler.

justanhduc avatar justanhduc commented on May 27, 2024

Hey @technojoe. Great job! Can you send a PR for this? Thanks!

from task-spooler.

justanhduc avatar justanhduc commented on May 27, 2024

@technojoe let me know if you need any help

from task-spooler.

technojoe avatar technojoe commented on May 27, 2024

#53

from task-spooler.

technojoe avatar technojoe commented on May 27, 2024

@justanhduc Anyone going to pull this in?

from task-spooler.

justanhduc avatar justanhduc commented on May 27, 2024

hey @technojoe. I'm a bit occupied these days. I will check it asap. Thanks a lot for your contrib!

from task-spooler.

justanhduc avatar justanhduc commented on May 27, 2024

#53

from task-spooler.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.