Write servlet in C (C/C ++ servlet page)

Source: Internet
Author: User

Write servlet in C (C/C ++ servlet page)

By mod_pebble

In a sentence written before development, pebble is designed to replace FastCGI. When you use this Web language,At least you have a certain understanding of C/C ++Otherwise, you may have to deal with problems you don't want to face, such as pointers, memory ....

What is CSP? What is mod_pebble?

Mod_pebble is an Apache-based module that provides rapid servlet development, session, cookie, and other operations, and supports dynamic modification. The file extension is. CSP, that is, C/C ++.
Servlet page.

CSP is a high-performance web development language.

With the help of mod_pebble, You can implement some common functions similar to ASP, JSP, and PHP, such as mixed HTML code

For example

<B> pebble test </B> <br>
<%! -- This is the first line and will not appear in the. c file -- %>

<% @ Include "Inc. CSP" %>

<%
{
Char * id = page-> getparam (page, "ID ");

If (ID)

Page-> write (page, "<br> id value: <B> % S </B> <br>", ID );

}
%>

Mod_pebble supports the following syntax:

1. CSP comments. Such comments will not appear in the generated. c file.
<%! -->
2. Lib path. Only one path can be set for one row.
<% @ Lib "D:/myproc/common/lib" %>

3. Include path. Only one path can be set for one row.
<% @ INC "D:/myproc/dow./ include" %>

4. Link Parameters
<% @ Link "-ldoodle" %>

5. Compiled Parameters
<% @ Comp "-G2" %>

6. a csp file is included. The CSP file does not generate the main running function of _ cspservice (). If the include file is changed, it cannot be loaded dynamically. Restart Apache.

<% @ Include "Inc. CSP" %>

7. Code Section
<% Int I;... %>

8. You can declare a function in the function section (we recommend using Lib for extension)
<%! Int Foo (void)... %>

CSP Operating Mechanism

Program the macro script first, generate the C source file code, then compile the code into a dynamic link library using gcc, and load and run the code using Apache DSO. the syntax is completely the C style. Therefore, CSPs can complete everything that can be done in C language.

How to install?

First, if it is a win32platform, install mingw, add the path of gcc.exe of mingwto the PATH variable, install apache2 (currently only apache2 is supported, and development of apache1 is not done yet), and modify httpd. conf.

Loadmodule pebble_module module/mod_pebble.dll
Addhandler pebble-script. CSP

Pebble_path D:/myproc/mod_pebble/bin

Copy mod_pebble.dll to the module directory under apache2, and pebble_path is the buffer directory of pebble. Therefore, you must provide read and write permissions for the directory for apache2 running users. Otherwise, compilation cannot be performed, set CSP. copy the DLL to the WINNT directory.

Copy CSP. H to the include directory of mingw, and copy libcsp. A to the lib directory of mingw. Now we can create a test file hello. CSP.

<% PAGE-> write (page, "Hello, Pebble! /N "); %>

When you open hello. CSP, print hello, pebbe! The installation is successful.

Since it was just developed and not tested frequently, so what problems do you encounter and want to be able to instantly report to me (31-boy@163.com)

Some development instructions:

From the very beginning, pebble was designed to adapt to high-intensity working environments. therefore, the most insecure C language is used for language selection. When you choose pebble, some headaches may follow you. I hope you can pay attention to the following:

Pebble provides two memory pools with different lifecycles: page and session.

The lifecycle of the page is in the current page. Application Method: void newmem = page-> getpageres (page, 128). Therefore, do not use the memory applied in the page on the session!

The application method void newmem =
Page-& gt; getsessres (page, 128 );

The most important thing is:Please do not try to release the memory you have applied for from the above two memory pools! If you are using your own malloc memory, please manage it on your own!

Do not call all functions starting with '_' manually unless you know
Pebble!

Other pending...

Pebble is completed in a week, so there are many bugs and I still have a lot of work to do.

For example, prevent secondary compilation, module inspection, idle module maintenance, other thread security, database connection pool, and so on. After I have time, I can make up for it.

 

Up. daze God

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.