📄 wshare.html
字号:
<html><!-- #BeginTemplate "/Templates/tmpl.dwt" --><head><!-- #BeginEditable "doctitle" --> <title>PTypes: wshare</title><!-- #EndEditable --> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link rel="stylesheet" href="styles.css"></head><body bgcolor="#FFFFFF" leftmargin="40" marginwidth="40"><p><a href="../index.html"><img src="title-1.7.gif" width="213" height="34" alt="C++ Portable Types Library (PTypes) Version 1.7" border="0"></a> <hr noshade><!-- #BeginEditable "body" --> <p class="hpath"><a href="index.html">Top</a>: PTypes demo program -- wshare</p><p><b><br>Overview</b></p><blockquote> <p><span class="lang">Wshare</span> is a simple multithreaded web server (HTTP daemon) that uses almost all functional parts of the library and serves as an example of using PTypes. <span class="lang">Wshare</span> supports protocol versions up to HTTP/1.1. It provides simple means of sharing files over the web, but it lacks server-side scripting and authentication functionality.</p><p><i> The program is covered by the same license as PTypes. The authors can not be responsible for any data loss or accidental disclosure of confidential information caused by this software. It is provided `as is' with the hope that it can be useful both as a library demo program and a simple web server.</i></p><p>The sources are in <span class="lang">./wshare</span>. On Unix, this application is being built along with the library and is being copied to <span class="lang">./bin</span>. For MSVC, a separate project is provided as a part of the PTypes workspace. For BCC on Windows, the makefile is <span class="lang">wshare/wshare.mak</span>.</p><p><span class="lang">Wshare</span> does not require any special installation or configuration procedures and can be easily run from the command line with at least one parameter: the directory you wish to share over the web. Note that <span class="lang">wshare</span> does not understand <span class="lang">.htaccess</span> or any other configuration files in your directories, so the web site you might previously have will run with <span class="lang">wshare</span>'s default configuration and access rights.</p><p><span class="lang">Wshare</span> is scalable: you can write your own handlers for new HTTP methods, nonexistent (virtual) paths and for specific file extensions. Currently custom modules can be incorporated into <span class="lang">wshare</span> only at compile-time. Please, see <span class="lang">wshare/modules.h</span> and <span class="lang">wshare/request.h</span> for details. Also take a look at the sample compile-time module <span class="lang">wshare/mod_about.cxx.</span></p><p>Note: there is a <a href="http://sourceforge.net/tracker/index.php?func=detail&aid=595502&group_id=56008&atid=493273">known problem</a> on Linux with GCC 2.96: <span class="lang">wshare</span> may crash under heavy load if compiled with this version of GCC. It is recommended to use GCC 2.95 instead.</p><p>Please, run the program to see the summary of the command-line options.</p></blockquote><p><b><br>Running on Unix</b></p><blockquote> <p>By default the daemon is trying to bind to port 80, which is a privileged port on Unix. You will have to either run it as root, or to specify a port number higher than 1024 with the option <span class="lang">-p <i>port-number</i></span>, e.g. <span class="lang">-p 8080</span>.</p><p><span class="lang">Wshare</span> uses Unix's syslog to log error messages. The HTTP access log goes to stderr, which can be overridden with <span class="lang">-o <i>logfile</i></span>.</p><p><span class="lang">Wshare</span> can also daemonize itself, i.e. detach from the console and remain active after the user logs out. Use option <span class="lang">-D</span> to daemonize the program. After that, the only way to stop the server is to send a SIGKILL signal, i.e. determine the process ID with <span class="lang">ps</span> and then invoke <span class="lang">kill -KILL <i>PID</i></span>. On some systems you will need to use <span class="lang">ps</span> with the option that specifies your user ID.</p><p>Note, that many Unix systems `lock' the port for some time even after the server exits. Normally this lasts few minutes, so if you repeatedly run <span class="lang">wshare</span> on the same port, most likely you will get an error message saying that the address is in use.</p></blockquote><p><b><br>Running on Windows</b></p><blockquote> <p>On Windows <span class="lang">wshare</span> runs as a simple console application. All you can do with <span class="lang">wshare</span> on Windows is to specify a different port to bind to with option <span class="lang">-p <i>port-number</i></span> and to redirect the HTTP access log to some file with option <span class="lang">-o <i>logfile</i></span>. Redirecting the access log to a file instead of writing it to the console window can speed up the server.</p></blockquote><p><b><br>Common features</b></p><blockquote> <p>By default <span class="lang">wshare</span> does not generate directory indexes (analogue of `Option Indexes' in Apache's configuration), which means the directory must have a default index file named as either of: <span class="lang">index.html</span>, <span class="lang">Index.html</span> or <span class="lang">default.htm</span>. Directory indexes can be allowed by specifying option <span class="lang">-d</span>. In this case, if the directory does not have any of the default index files listed above, <span class="lang">wshare</span> will generate a page with the list of files the directory contains.</p><p>If you don't want default index files at all, use option <span class="lang">-x</span> in the command line: the server will then show the directory indexes, like if you specified an empty "DirectoryIndex" directive with Apache.</p><p>You can limit the number of simultaneous connections with option <span class="lang">-n <i>num</i></span>, which is 30 by default. When the number of connections reaches <span class="lang">num/2</span> , the server stops supporting persistent connections. When it reaches <span class="lang">num</span>, the server sends "504 Service unavailable" to the client. And finally, when the number of connection requests reaches <span class="lang">num * 2</span>, wshare simply aborts the connection by closing the socket.</p><p>You can get the current status of the server by requesting <span class="lang">http://localhost/.wstat</span> in your browser. <span class="lang">Wshare</span> responds to this request only if the client is on the same host as the server, i.e. <span class="lang">localhost</span> or 127.0.0.1.</p><p>Some other features are hardcoded into <span class="lang">wshare</span> and can be changed only by recompiling it. The list of default index files can be found in <span class="lang">wshare/config.cxx</span>, and the file extension-to-MIME translation table is in <span class="lang">wshare/mimetable.cxx</span>. An awk script <span class="lang">wshare/mimetable.awk</span> is provided to translate an apache-style <span class="lang">mime.conf</span> file into C++ code that can be linked with <span class="lang">wshare</span>.</p></blockquote><p><b><br>Examples (Unix)</b></p><blockquote> <p>The simplest usage:</p><blockquote> <p class="lang">wshare ./</p></blockquote><p>Quickly share your files through port 8080 and ignore any index.html files in the directories:</p><blockquote> <p class="lang">wshare -x -p 8080 ~/mydocs</p></blockquote><p>Run a real server for real users (must be root on Unix):</p><blockquote> <p class="lang">wshare -D -n 100 -o /var/log/wshare-access.log /usr/local/www</p></blockquote><p>BE CAREFUL and double check the directory you are opening to the world.</p></blockquote><!-- #EndEditable --><hr size="1"><a href="../index.html" class="ns">PTypes home</a></body><!-- #EndTemplate --></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -