Differences From
Artifact [80adbc5ad3]:
5 5 local struct srv
6 6 local struct cfgcache {
7 7 secret: pstring
8 8 pol_sec: secmode.t
9 9 pol_reg: bool
10 10 credmgd: bool
11 11 maxupsz: intptr
12 + poolinitsz: intptr
12 13 instance: pstring
13 14 overlord: &srv
14 15 ui_cue_staff: pstring
15 16 ui_cue_founder: pstring
16 17 ui_hue: uint16
17 18 nranks: uint16
18 19 maxinvites: uint16
................................................................................
20 21 }
21 22 local struct srv {
22 23 sources: lib.mem.ptr(lib.store.source)
23 24 webmgr: lib.net.mg_mgr
24 25 webcon: &lib.net.mg_connection
25 26 cfg: cfgcache
26 27 id: rawstring
28 + pool: lib.mem.pool
27 29 }
28 30
29 31 terra cfgcache:free() -- :/
30 32 self.secret:free()
31 33 self.instance:free()
32 34 self.ui_cue_staff:free()
33 35 self.ui_cue_founder:free()
................................................................................
306 308
307 309 terra convo:confirm(title: pstring, msg: pstring, cancel: pstring)
308 310 var conf = data.view.confirm {
309 311 title = title;
310 312 query = msg;
311 313 cancel = cancel;
312 314 }
313 - var ti: lib.str.acc ti:compose('confirm :: ', title)
314 - var body = conf:tostr() defer body:free()
315 + var ti: lib.str.acc ti:pcompose(&self.srv.pool,'confirm :: ', title)
316 + var body = conf:poolstr(&self.srv.pool) -- defer body:free()
315 317 var cf = [convo.page] {
316 318 title = ti:finalize();
317 319 class = lib.str.plit 'query';
318 320 body = body; cache = false;
319 321 }
320 322 self:stdpage(cf)
321 - cf.title:free()
323 + --cf.title:free()
324 +end
325 +
326 +terra convo:stra(sz: intptr) -- convenience function
327 + var s: lib.str.acc
328 + s:pool(&self.srv.pool,sz)
329 + return s
322 330 end
323 331
324 332 convo.methods.assertpow = macro(function(self, pow)
325 333 return quote
326 334 var ok = true
327 335 if self.aid == 0 or self.who.rights.powers.[pow:asvalue()]() == false then
328 336 ok = false
................................................................................
330 338 end
331 339 in ok end
332 340 end)
333 341
334 342 -- CALL ONLY ONCE PER VAR
335 343 terra convo:postv(name: rawstring)
336 344 if self.varbuf.ptr == nil then
337 - self.varbuf = lib.mem.heapa(int8, self.msg.body.len + self.msg.query.len)
345 + self.varbuf = self.srv.pool:alloc(int8, self.msg.body.len + self.msg.query.len)
338 346 self.vbofs = self.varbuf.ptr
339 347 end
340 348 var o = lib.net.mg_http_get_var(&self.msg.body, name, self.vbofs, self.varbuf.ct - (self.vbofs - self.varbuf.ptr))
341 349 if o > 0 then
342 350 var r = self.vbofs
343 351 self.vbofs = self.vbofs + o + 1
344 352 @(self.vbofs - 1) = 0
................................................................................
349 357 terra convo:ppostv(name: rawstring)
350 358 var s,l = self:postv(name)
351 359 return pstring { ptr = s, ct = l }
352 360 end
353 361
354 362 terra convo:getv(name: rawstring)
355 363 if self.varbuf.ptr == nil then
356 - self.varbuf = lib.mem.heapa(int8, self.msg.query.len + self.msg.body.len)
364 + self.varbuf = self.srv.pool:alloc(int8, self.msg.query.len + self.msg.body.len)
357 365 self.vbofs = self.varbuf.ptr
358 366 end
359 367 var o = lib.net.mg_http_get_var(&self.msg.query, name, self.vbofs, self.varbuf.ct - (self.vbofs - self.varbuf.ptr))
360 368 if o > 0 then
361 369 var r = self.vbofs
362 370 self.vbofs = self.vbofs + o + 1
363 371 @(self.vbofs - 1) = 0
................................................................................
551 559 var livelast_p = lib.http.findheader(msg, 'X-Live-Last-Arrival')
552 560 if livelast_p ~= nil and livelast_p.ptr ~= nil then
553 561 var ll, ok = lib.math.decparse(pstring{ptr = livelast_p.ptr, ct = livelast_p.ct - 1})
554 562 if ok then co.live_last = ll end
555 563 end
556 564
557 565
558 - var uridec = lib.mem.heapa(int8, msg.uri.len) defer uridec:free()
566 + var uridec = server.pool:alloc(int8, msg.uri.len)
559 567 var urideclen = lib.net.mg_url_decode(msg.uri.ptr, msg.uri.len, uridec.ptr, uridec.ct, 1)
560 568
561 569 var uri = uridec
562 570 if urideclen == -1 then
563 571 for i = 0,msg.uri.len do
564 572 if msg.uri.ptr[i] == @'+'
565 573 then uri.ptr[i] = @' '
................................................................................
677 685 bsr:free()
678 686 upmap:free()
679 687 end
680 688 end
681 689 end
682 690
683 691 route.dispatch_http(&co, uri, co.method)
692 +
693 + ::fail::
684 694 if co.uploads.run > 0 then
685 695 for i=0,co.uploads.sz do
686 696 co.uploads(i).filename:free()
687 697 co.uploads(i).field:free()
688 698 end
689 699 co.uploads:free()
690 700 end
691 701
692 - ::fail::
693 702 if co.aid ~= 0 then lib.mem.heapf(co.who) end
694 - if co.varbuf.ptr ~= nil then co.varbuf:free() end
695 - if co.navbar.ptr ~= nil then co.navbar:free() end
703 + -- if co.varbuf.ptr ~= nil then co.varbuf:free() end
704 + -- if co.navbar.ptr ~= nil then co.navbar:free() end
696 705 co.actorcache:free()
706 + server.pool:clear()
697 707 end
698 708 end
699 709 end;
700 710 }
701 711
702 712 local terra cfg(s: &srv, befile: rawstring)
703 713 lib.report('configuring backends from ', befile)
................................................................................
853 863 lib.bail('could not connect to any data sources!')
854 864 end
855 865 end
856 866
857 867 terra srv:start(iname: rawstring)
858 868 self:conprep(lib.store.prepmode.full)
859 869 self.cfg:init(self)
870 + self.pool:init(self.cfg.poolinitsz)
860 871 var dbbind = self:conf_get('bind')
861 872 if iname == nil then iname = lib.proc.getenv('parsav_instance') end
862 873 if iname == nil then
863 874 self.id = self.cfg.instance.ptr;
864 875 -- let this leak -- it'll be needed for the lifetime of the process anyway
865 876 else self.id = iname end
866 877
................................................................................
890 901 terra srv:shutdown()
891 902 lib.net.mg_mgr_free(&self.webmgr)
892 903 for i=0,self.sources.ct do var src = self.sources.ptr + i
893 904 lib.report('closing data source ', src.id.ptr, '(', src.backend.id, ')')
894 905 src:close()
895 906 end
896 907 self.sources:free()
908 + self.pool:free()
897 909 end
898 910
899 911 terra cfgcache:cfint(name: rawstring, default: intptr)
900 912 var str = self.overlord:conf_get(name)
901 913 if str.ptr ~= nil then
902 914 var i,ok = lib.math.decparse(str)
903 915 if ok then default = i else
904 916 lib.warn('invalid configuration setting ',name,'="',{str.ptr,str.ct},'", expected integer; using default value instead')
905 917 end
906 918 str:free()
919 + end
920 + return default
921 +end
922 +
923 +terra cfgcache:cffsz(name: rawstring, default: intptr)
924 + var str = self.overlord:conf_get(name)
925 + if str:ref() then
926 + var sz, ok = lib.math.fsz_parse(str)
927 + if ok then default = sz else
928 + lib.warn('invalid configuration setting ',name,'="',{str.ptr,str.ct},'", expected byte length; using default value instead')
929 + end
930 + str:free()
907 931 end
908 932 return default
909 933 end
910 934
911 935 terra cfgcache:cfbool(name: rawstring, default: bool)
912 936 var str = self.overlord:conf_get(name)
913 937 if str.ptr ~= nil then
................................................................................
937 961 if lib.str.cmp(sreg.ptr, 'managed') == 0
938 962 then self.credmgd = true
939 963 else self.credmgd = false
940 964 end
941 965 sreg:free()
942 966 end end
943 967
944 - do self.maxupsz = [1024 * 100] -- 100 kilobyte default
945 - var sreg = self.overlord:conf_get('maximum-artifact-size')
946 - if sreg:ref() then
947 - var sz, ok = lib.math.fsz_parse(sreg)
948 - if ok then self.maxupsz = sz else
949 - lib.warn('invalid configuration value for maximum-artifact-size; keeping default 100K upload limit')
950 - end
951 - sreg:free() end
952 - end
968 + self.maxupsz = self:cffsz('maximum-artifact-size', [1024 * 100]) -- 100 kilobyte default
969 + self.poolinitsz = self:cffsz('server-pool-size-initial', [1024 * 10]) -- 10 kilobyte default
953 970
954 971 self.pol_sec = secmode.lockdown
955 972 var smode = self.overlord:conf_get('policy-security')
956 973 if smode.ptr ~= nil then
957 974 if lib.str.cmp(smode.ptr, 'public') == 0 then
958 975 self.pol_sec = secmode.public
959 976 elseif lib.str.cmp(smode.ptr, 'private') == 0 then
................................................................................
970 987 self.nranks = self:cfint('user-ranks',10)
971 988 self.maxinvites = self:cfint('max-invites',64)
972 989
973 990 var webmaster = self.overlord:conf_get('master')
974 991 if webmaster:ref() then defer webmaster:free()
975 992 var wma = self.overlord:actor_fetch_xid(webmaster)
976 993 if not wma then
977 - lib.warn('the webmaster specified in the configuration store does not seem to exist or is not known to this instance; preceding as if no master defined. if the master is a remote user, you can rectify this with the `actor ',{webmaster.ptr,webmaster.ct},' instantiate` and `conf refresh` commands')
994 + lib.warn('the webmaster specified in the configuration store does not seem to exist or is not known to this instance; preceding as if no master defined. if the master is a remote user, you can rectify this with the `actor "',{webmaster.ptr,webmaster.ct},'" instantiate` and `conf refresh` commands')
978 995 else
979 996 self.master = wma(0).id
980 997 wma:free()
981 998 end
982 999 end
983 1000
984 1001 self.ui_cue_staff = self.overlord:conf_get('ui-profile-cue-staff')