Project homepage Mailing List  Warmcat.com  API Docs  Github Mirror 
{"schema":"libjg2-1", "vpath":"/git/", "avatar":"/git/avatar/", "alang":"", "gen_ut":1753413196, "reponame":"libwebsockets", "desc":"libwebsockets lightweight C networking library", "owner": { "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" },"url":"https://libwebsockets.org/repo/libwebsockets", "f":3, "items": [ {"schema":"libjg2-1", "cid":"73e13e98534b61c68fb3845842355526", "commit": {"type":"commit", "time": 1582306361, "time_ofs": 0, "oid_tree": { "oid": "a5149065888c6a9618c2c990ff698206bd878a38", "alias": []}, "oid":{ "oid": "6a737b7ca6907c1b0f98d4ecb222dcb67546c8c8", "alias": []}, "msg": "lwsac: add lwsac_extend api", "sig_commit": { "git_time": { "time": 1582306361, "offset": 0 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }, "sig_author": { "git_time": { "time": 1579893832, "offset": 0 }, "name": "Andy Green", "email": "andy@warmcat.com", "md5": "c50933ca2aa61e0fe2c43d46bb6b59cb" }}, "body": "lwsac: add lwsac_extend api" , "diff": "diff --git a/include/libwebsockets/lws-lwsac.h b/include/libwebsockets/lws-lwsac.h\nindex 1c0d69b..a59e459 100644\n--- a/include/libwebsockets/lws-lwsac.h\n+++ b/include/libwebsockets/lws-lwsac.h\n@@ -1,7 +1,7 @@\n /*\n * libwebsockets - small server side websockets and web server implementation\n *\n- * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n+ * Copyright (C) 2010 - 2020 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n@@ -198,6 +198,38 @@ lwsac_reference(struct lwsac *head);\n LWS_VISIBLE LWS_EXTERN void\n lwsac_unreference(struct lwsac **head);\n \n+/**\n+ * lwsac_extend() - try to increase the size of the last block\n+ *\n+ * \u005cparam head: pointer to the lwsac list object\n+ * \u005cparam amount: amount to try to increase usage for\n+ *\n+ * This will either increase the usage reservation of the last allocated block\n+ * by amount and return 0, or fail and return 1.\n+ *\n+ * This is very cheap to call and is designed to optimize usage after a static\n+ * struct for vari-sized additional content which may flow into an additional\n+ * block in a new chunk if necessary, but wants to make the most of the space\n+ * in front of it first to try to avoid gaps and the new chunk if it can.\n+ *\n+ * The additional area if the call succeeds will have been memset to 0.\n+ *\n+ * To use it, the following must be true:\n+ *\n+ * - only the last lwsac use can be extended\n+ *\n+ * - if another use happens inbetween the use and extend, it will break\n+ *\n+ * - the use cannot have been using backfill\n+ *\n+ * - a user object must be tracking the current allocated size of the last use\n+ * (lwsac doesn't know it) and increment by amount if the extend call succeeds\n+ *\n+ * Despite these restrictions this can be an important optimization for some\n+ * cases\n+ */\n+LWS_VISIBLE LWS_EXTERN int\n+lwsac_extend(struct lwsac *head, int amount);\n \n /* helpers to keep a file cached in memory */\n \ndiff --git a/lib/misc/lwsac/lwsac.c b/lib/misc/lwsac/lwsac.c\nindex 426fdb3..3ca48a7 100644\n--- a/lib/misc/lwsac/lwsac.c\n+++ b/lib/misc/lwsac/lwsac.c\n@@ -1,7 +1,7 @@\n /*\n * libwebsockets - small server side websockets and web server implementation\n *\n- * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n+ * Copyright (C) 2010 - 2020 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n@@ -69,6 +69,29 @@ lwsac_get_next(struct lwsac *lac)\n \treturn lac-\u003enext;\n }\n \n+int\n+lwsac_extend(struct lwsac *head, int amount)\n+{\n+\tstruct lwsac_head *lachead;\n+\tstruct lwsac *bf;\n+\n+\tassert(head);\n+\tlachead \u003d (struct lwsac_head *)\u0026head[1];\n+\n+\tbf \u003d lachead-\u003ecurr;\n+\tassert(bf);\n+\n+\tif (bf-\u003ealloc_size - bf-\u003eofs \u003c lwsac_align(amount))\n+\t\treturn 1;\n+\n+\t/* memset so constant folding never sees uninitialized data */\n+\n+\tmemset(((uint8_t *)bf) + bf-\u003eofs, 0, lwsac_align(amount));\n+\tbf-\u003eofs +\u003d lwsac_align(amount);\n+\n+\treturn 0;\n+}\n+\n static void *\n _lwsac_use(struct lwsac **head, size_t ensure, size_t chunk_size, char backfill)\n {\ndiff --git a/lib/misc/lwsac/private-lib-misc-lwsac.h b/lib/misc/lwsac/private-lib-misc-lwsac.h\nindex 8c09595..026e7ad 100644\n--- a/lib/misc/lwsac/private-lib-misc-lwsac.h\n+++ b/lib/misc/lwsac/private-lib-misc-lwsac.h\n@@ -1,7 +1,7 @@\n /*\n * libwebsockets - small server side websockets and web server implementation\n *\n- * Copyright (C) 2010 - 2019 Andy Green \u003candy@warmcat.com\u003e\n+ * Copyright (C) 2010 - 2020 Andy Green \u003candy@warmcat.com\u003e\n *\n * Permission is hereby granted, free of charge, to any person obtaining a copy\n * of this software and associated documentation files (the \u0022Software\u0022), to\n@@ -38,18 +38,26 @@\n * count reaches zero.\n */\n \n+/*\n+ * One of these per chunk\n+ */\n+\n struct lwsac {\n \tstruct lwsac *next;\n \tstruct lwsac *head; /* pointer back to the first chunk */\n-\tsize_t alloc_size;\n+\tsize_t alloc_size; /* alloc size of the whole chunk */\n \tsize_t ofs; /* next writeable position inside chunk */\n };\n \n+/*\n+ * One of these per lwsac, at start of first chunk\n+ */\n+\n struct lwsac_head {\n-\tstruct lwsac *curr; /* applies to head chunk only */\n-\tsize_t total_alloc_size; /* applies to head chunk only */\n-\tint refcount; /* applies to head chunk only */\n-\tint total_blocks; /* applies to head chunk only */\n+\tstruct lwsac *curr;\n+\tsize_t total_alloc_size;\n+\tint refcount;\n+\tint total_blocks;\n \tchar detached; /* if our refcount gets to zero, free the chunk list */\n };\n \n","s":{"c":1753413196,"u": 2340}} ],"g": 4103,"chitpc": 0,"ehitpc": 0,"indexed":0 , "ab": 0, "si": 0, "db":0, "di":0, "sat":0, "lfc": "0000"}