Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ MT-multithreading and servers » Skylark - serving CSS style sheets
Skylark - serving CSS style sheets [message #40281] Mon, 15 July 2013 08:20 Go to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Hi,

I'm working with SCGI, so I'd prefere to serve ALL of my files directly from skylark and not let the webserver do it.
How can this be done ?
Is it possible to "insert" somehow the file inside compiled app and serve it directly, without saving to disk before as is done for witz templates ?
Re: Skylark - serving CSS style sheets [message #40284 is a reply to message #40281] Mon, 15 July 2013 14:17 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

mdelfede wrote on Mon, 15 July 2013 08:20

Hi,

I'm working with SCGI, so I'd prefere to serve ALL of my files directly from skylark and not let the webserver do it.
How can this be done ?

Hi,

Have a look at Skylark/static.icpp. There is a handler which can be used to serve styles, javascripts and images. Also, it contains some support for adding links to witz templates that allow for aggressive (configurable) usage of browser caches.
mdelfede wrote on Mon, 15 July 2013 08:20

Is it possible to "insert" somehow the file inside compiled app and serve it directly, without saving to disk before as is done for witz templates ?

Any file can be included into executable using *.brc file. Then you can serving simply by passing the data to Http::Content().

Best regards,
Honza
Re: Skylark - serving CSS style sheets [message #40285 is a reply to message #40284] Mon, 15 July 2013 14:22 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Hi, Honza,

thank you very much for answeriny.
I already use somewhere the .brc files, but I think that it would be better to have some more 'smart' way to handle styles, javascript and image files, without having to do manually all the .brc mechanics.

Ciao

Max
Re: Skylark - serving CSS style sheets [message #40293 is a reply to message #40285] Mon, 15 July 2013 21:58 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

mdelfede wrote on Mon, 15 July 2013 14:22

Hi, Honza,

thank you very much for answeriny.
I already use somewhere the .brc files, but I think that it would be better to have some more 'smart' way to handle styles, javascript and image files, without having to do manually all the .brc mechanics.

Ciao

Max


Manually? How can it be any easier than this:
BINARY_MASK(scripts, "js/*.js")
BINARY_MASK(styles, "css/*.css")
BINARY_MASK(images, "img/*.jpg")

Smile

Honza

[Updated on: Mon, 15 July 2013 21:58]

Report message to a moderator

Re: Skylark - serving CSS style sheets [message #40294 is a reply to message #40293] Mon, 15 July 2013 22:48 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Ah! Never used BINARY_MASK.... I'll try it !

Thank you Honza!

Max
Re: Skylark - serving CSS style sheets [message #40296 is a reply to message #40293] Tue, 16 July 2013 08:31 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 307
Registered: July 2009
Senior Member
dolik.rce wrote on Mon, 15 July 2013 21:58


Manually? How can it be any easier than this:
BINARY_MASK(scripts, "js/*.js")
BINARY_MASK(styles, "css/*.css")
BINARY_MASK(images, "img/*.jpg")




It would be nice to extend BINARY macro the same way that IMAGE_ID works (to save also name of binary data).
With images you can use GetImlImage(name) to find image by it's name.

Re: Skylark - serving CSS style sheets [message #40298 is a reply to message #40296] Tue, 16 July 2013 08:33 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
It does already.... you've an array of names too.

Max
Re: Skylark - serving CSS style sheets [message #40300 is a reply to message #40298] Tue, 16 July 2013 09:04 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 307
Registered: July 2009
Senior Member
Yes, you are right.
Re: Skylark - serving CSS style sheets [message #40301 is a reply to message #40300] Tue, 16 July 2013 09:06 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
This is my code to serve .css coming from .brc :

SKYLARK(Styles, "styles/*")
{
	static VectorMap<String, String> cssMap;
	static bool init = false;
	
	if(!init)
	{
		for(int i = 0; i < styles_count; i++)
			cssMap.Add(styles_files[i], String(styles[i], styles_length[i]));
		init = true;
	}
	
	int i = cssMap.Find(http[0]);
	if(i >= 0)
		http.Content("text/css", cssMap[i]);
}
Re: Skylark - serving CSS style sheets [message #40302 is a reply to message #40301] Tue, 16 July 2013 09:29 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 307
Registered: July 2009
Senior Member
mdelfede wrote on Tue, 16 July 2013 09:06

This is my code to serve .css coming from .brc :

SKYLARK(Styles, "styles/*")
{
	static VectorMap<String, String> cssMap;
	static bool init = false;
	
	if(!init)
	{
		for(int i = 0; i < styles_count; i++)
			cssMap.Add(styles_files[i], String(styles[i], styles_length[i]));
		init = true;
	}
	
	int i = cssMap.Find(http[0]);
	if(i >= 0)
		http.Content("text/css", cssMap[i]);
}




Since Skylark is multi thread, your init section is risky. You should use ONCELOCK.
Re: Skylark - serving CSS style sheets [message #40303 is a reply to message #40302] Tue, 16 July 2013 09:31 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Right Wink
Re: Skylark - serving CSS style sheets [message #40304 is a reply to message #40303] Tue, 16 July 2013 09:33 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 307
Registered: July 2009
Senior Member
And VectorMap is also not thread safe, so you should add INTERLOCK when you are accessing it.

Re: Skylark - serving CSS style sheets [message #40305 is a reply to message #40304] Tue, 16 July 2013 09:35 Go to previous messageGo to next message
mdelfede is currently offline  mdelfede
Messages: 1259
Registered: September 2007
Senior Contributor
Zbych wrote on Tue, 16 July 2013 09:33

And VectorMap is also not thread safe, so you should add INTERLOCK when you are accessing it.




Are you sure ???? I'm using VectorMap everywhere, and I think it should be safe reading it, of course NOT writing it, without INTERLOCK. Otherwise, I should spread interlocks in tons of code lines....
Re: Skylark - serving CSS style sheets [message #40306 is a reply to message #40305] Tue, 16 July 2013 09:45 Go to previous messageGo to next message
Zbych is currently offline  Zbych
Messages: 307
Registered: July 2009
Senior Member
I am not sure, we have to ask someone with greater experience. But to be save I usually use a template that adds locking to a container and I don't have to do it manually.

Re: Skylark - serving CSS style sheets [message #40352 is a reply to message #40306] Mon, 22 July 2013 22:31 Go to previous message
mirek is currently offline  mirek
Messages: 12105
Registered: November 2005
Ultimate Member
Zbych wrote on Tue, 16 July 2013 03:45

I am not sure, we have to ask someone with greater experience. But to be save I usually use a template that adds locking to a container and I don't have to do it manually.




Most objects in U++ allow many readers and single writer, which is sort of sanity standard with multithreading anyway (here refering to other frameworks...)

Mirek
Previous Topic: How to pass vector/array of structs to witz?
Next Topic: File upload
Goto Forum:
  


Current Time: Wed Nov 20 08:38:35 CET 2019

Total time taken to generate the page: 0.01509 seconds