1%template for producing IEEE-format articles using LaTeX. 2%written by Matthew Ward, CS Department, Worcester Polytechnic Institute. 3%use at your own risk. Complaints to /dev/null. 4%make two column with no page numbering, default is 10 point 5%\documentstyle[times]{article} 6\documentstyle[twocolumn]{article} 7%\pagestyle{myheadings} 8 9%set dimensions of columns, gap between columns, and space between paragraphs 10%\setlength{\textheight}{8.75in} 11\setlength{\textheight}{9.0in} 12\setlength{\columnsep}{0.25in} 13\setlength{\textwidth}{6.45in} 14\setlength{\footheight}{0.0in} 15\setlength{\topmargin}{0.0in} 16\setlength{\headheight}{0.0in} 17\setlength{\headsep}{0.0in} 18\setlength{\oddsidemargin}{0in} 19%\setlength{\oddsidemargin}{-.065in} 20%\setlength{\oddsidemargin}{-.17in} 21%\setlength{\parindent}{0pc} 22 23%I copied stuff out of art10.sty and modified them to conform to IEEE format 24 25\makeatletter 26%as Latex considers descenders in its calculation of interline spacing, 27%to get 12 point spacing for normalsize text, must set it to 10 points 28\def\@normalsize{\@setsize\normalsize{12pt}\xpt\@xpt 29\abovedisplayskip 10pt plus2pt minus5pt\belowdisplayskip \abovedisplayskip 30\abovedisplayshortskip \z@ plus3pt\belowdisplayshortskip 6pt plus3pt 31minus3pt\let\@listi\@listI} 32 33%need an 11 pt font size for subsection and abstract headings 34\def\subsize{\@setsize\subsize{12pt}\xipt\@xipt} 35 36%make section titles bold and 12 point, 2 blank lines before, 1 after 37\def\section{\@startsection {section}{1}{\z@}{24pt plus 2pt minus 2pt} 38{12pt plus 2pt minus 2pt}{\large\bf}} 39 40%make subsection titles bold and 11 point, 1 blank line before, 1 after 41\def\subsection{\@startsection {subsection}{2}{\z@}{12pt plus 2pt minus 2pt} 42{12pt plus 2pt minus 2pt}{\subsize\bf}} 43\makeatother 44 45\newcommand{\ignore}[1]{} 46%\renewcommand{\thesubsection}{\arabic{subsection}.} 47 48\begin{document} 49 50 51 52%don't want date printed 53\date{} 54 55%make title bold and 14 pt font (Latex default is non-bold, 16 pt) 56\title{ 57{\large \em *** DRAFT : To appear in Freenix'02 ***} \\ 58{\Large \bf SWILL: A Simple Embedded Web Server Library}} 59 60%for single author (just remove % characters) 61\author{Sotiria Lampoudi and David M. Beazley \\ 62{\em Department of Computer Science} \\ 63{\em University of Chicago }\\ 64{\em Chicago, Illinois 60637 }\\ 65{\tt \{slampoud,beazley\}@cs.uchicago.edu }} 66 67\maketitle 68 69\thispagestyle{empty} 70\begin{abstract} 71 72{\em 73We present SWILL, a lightweight programming library that adds a simple 74embedded web server capability to C and C++ programs. Using SWILL, it 75is possible to add Internet accessibility to programs that are poorly 76matched to more traditional methods of web programming such as CGI 77scripting or web server plugin modules. SWILL also makes it easy for 78programmers to add web-based monitoring, diagnostics, and debugging 79capabilities to software not normally associated with internet 80programming. 81We like to think of SWILL as an attempt to turn 82the problem on its head: traditionally, the web server came first, the 83``programs'' later; in our approach, the application is written first, and the 84server integrated last. For some types of applications, this 85approach is far more painless. 86In this paper, we provide an overview of the SWILL 87library and describe how we have used it to provide web access to a 88variety of applications including scientific simulation software, 89a compiler, and a hardware emulator for teaching operating systems. 90} 91 92\end{abstract} 93 94\section{Introduction} 95 96With the growth and popularity of the web, many software developers 97are interested in building web-based interfaces to their applications. 98However, much of the effort involved in doing this seems to be spent figuring 99out how to integrate an application into an existing web server using 100CGI scripts, server plugin modules, or some sort of middleware 101layer. Although it is certainly possible to implement a web interface 102in this manner, a programmer may have to contort their application or 103implement a complicated runtime environment to make it work. To 104further complicate matters, there are certain applications in which 105web access would be useful, but which do not really fit into the standard mold 106of an internet application. Examples might include simulators, long 107running scientific programs, and compilers. 108 109Instead of figuring out how to integrate an application with a 110web server, an alternative approach might be to flip the 111whole situation around and to ask what it would take to 112add a web server to an application as a programming library. If a web 113server could be added as a library, it might greatly simplify the task 114of creating web-accessible programs. 115For instance, since the the web 116server would be part of the application itself, there would be no need 117to worry about the installation and configuration of a complicated web 118server environment. A library would also make it easier to add web 119capabilities to programs that are not really intended to be internet 120applications, but where a web interface would be useful in providing 121remote accessibility or as a simple diagnostics tool. 122 123In this paper, we describe SWILL (Simple Web Interface Link Library). 124SWILL is a lightweight library we have developed that makes it easy to 125add a web server to C/C++ programs. It consists of a handful of C 126functions that are inserted into an application to make it web 127accessible. The implementation is intentionally minimal and is 128primarily intended for developers who would like to create a web 129interface without a lot of hassle. 130 131SWILL was initially written for use with high performance scientific 132simulation software \cite{beazley1}. However, the implementation is generic enough to be 133used in a variety of other applications--limited only by the 134programmer's imagination. For example, we have used SWILL in a 135compiler project to help with the debugging of parse tree data. 136It has also been used to monitor the internals of a hardware simulator 137for teaching operating systems. 138 139The rest of this paper provides a brief overview of SWILL followed by 140some examples of how we have used the library. At the end, we provide 141a brief overview of related work and future plans. 142 143\section{Library Introduction} 144 145The best way to introduce SWILL is with a simple example. Although 146the library contains about 25 functions, only a handful are needed to 147get started as shown in this ``Hello World'' example: 148 149\begin{verbatim} 150#include <swill.h> 151void hello(FILE *f) { 152 fprintf(f,"Hello World!\n"); 153} 154 155int main() { 156 swill_init(8080); 157 swill_handle("hello.txt",hello,0); 158 while (1) { 159 swill_serve(); 160 } 161} 162\end{verbatim} 163 164In this example, the web server is activated by calling {\tt 165swill\_init()} with a TCP port number. One or more documents are then 166registered with the server using {\tt swill\_handle()}. {\tt 167swill\_serve()} is then used to wait for a connection. When a 168connection is received, an appropriate handler function is invoked 169depending on the URL. In this case, a request for the document ``{\tt 170hello.txt}'' invokes the {\tt hello()} function and produces the 171output that you expect. 172 173If an application wants to perform other work in addition to checking 174for connections, a non-blocking polling function is used. 175For example: 176 177\begin{verbatim} 178while (1) { 179 swill_poll(); /* Requests? */ 180 ... 181 /* other work */ 182 ... 183} 184\end{verbatim} 185 186This approach allows the web interface to be easily inserted into 187applications that provide their own event or computation loops. 188For example, a 189scientific simulation might call {\tt swill\_poll()} at selected 190intervals during computation, but spend the rest of its time crunching 191numbers. 192 193There are no restrictions on the type of output a SWILL handler 194function may produce. However, the document type is implicitly determined 195by the suffix supplied to the {\tt swill\_handle()} function. For example, 196if a function produces HTML, the following code would be used: 197 198\begin{verbatim} 199void hello(FILE *f) { 200 fprintf(f,"<HTML><BODY>\n"); 201 fprintf(f,"<b>Hello World!</b>\n"); 202 fprintf(f,"</BODY></HTML>\n"); 203} 204 205int main() { 206 ... 207 swill_handle("hello.html",hello,0); 208 ... 209} 210\end{verbatim} 211 212Similarly, the following code produces a PNG image using the freely available GD library \cite{gd}: 213 214\begin{verbatim} 215void 216image(FILE *f) { 217 int black,white; 218 gdImagePtr im; 219 220 im = gdImageCreate(64,64); 221 black = gdImageColorAllocate(im, 222 0,0,0); 223 white = gdImageColorAllocate(im, 224 255,255,255); 225 gdImageLine(im,0,0,63,63,wht); 226 ... 227 gdImagePng(im,f); 228 gdImageDestroy(im); 229} 230 231int main() { 232 ... 233 swill_handle("image.png",image,0); 234 ... 235\end{verbatim} 236 237Since a programmer may want to reuse the same handler function for different web pages, SWILL allows an 238optional pointer to be passed to the handler functions. This pointer is used to pass 239application specific data or an object to the handler. For example, an application that created 240various types of data plots might look roughly like this: 241 242\begin{verbatim} 243void 244make_plot(FILE *f, void *clientdata) { 245 Plot *p = (Plot *) clientdata; 246 ... 247 // Generate plot 248 ... 249 write_plot(p,f); 250} 251 252int main() { 253 ... 254 e = new energy_plot(); 255 d = new density_plot(); 256 ... 257 swill_handle("energy.png",make_plot,e); 258 swill_handle("density.png",make_plot,d); 259 ... 260\end{verbatim} 261 262Although SWILL is primarily intended for dynamic content generation, 263it can also deliver individual files or files from a user-specified 264directory. For example, if a programmer wanted to register a specific 265file with the server, they would do this: 266 267\begin{verbatim} 268swill_file("foo.html","./htdocs/foo.html"); 269\end{verbatim} 270 271\noindent 272Similarly, a directory of files is registered as follows: 273 274\begin{verbatim} 275swill_directory("./htdocs") 276\end{verbatim} 277 278\noindent 279When a directory is registered, SWILL delivers files much like a 280traditional web-server. 281 282In certain applications, a programmer might want to receive HTTP query 283variables as input parameters (as might be supplied from an HTML 284form). SWILL automatically parses HTTP query strings in both GET and 285POST requests. To access query variables as strings, the following 286function is used: 287 288\begin{verbatim} 289char *swill_getvar(const char *name); 290\end{verbatim} 291 292\noindent 293However, a more convenient way to get form variables is to use {\tt 294swill\_getargs()} as shown in this example: 295 296\begin{verbatim} 297void adder(FILE *f) { 298 double x,y; 299 if (!swill_getargs("d(x)d(y)",&x,&y)) { 300 fprintf(f,"Missing values!\n"); 301 return; 302 } 303 fprintf(f,"%g + %g = %g\n", x,y,x+y); 304} 305\end{verbatim} 306 307\noindent 308The argument to {\tt swill\_getargs()} is a format string that 309specifies the types and names of form variables to be converted. If 310available, the variables are decoded, placed into C variables, and a 311success code returned. 312 313\section{Concurrency and I/O} 314 315SWILL is a single-threaded server that does not rely upon concurrency 316mechanisms such as forking or multithreading. This limitation is by 317design and is related to the goal of having a server that could be 318easily embedded into a variety of specialized applications such as 319parallel scientific codes, hardware emulators, and so forth. In these 320situations, the use of concurrency can introduce serious 321reliability and portability problems. For instance, an application 322may not be thread-safe, making it impossible to reliably execute a 323handler function in parallel with normal execution. Similarly, 324forking may be impractical in applications with heavy resource 325utilization or which rely upon interprocess communication (e.g., 326message passing). 327 328Because of the single-threaded execution model, the implementation of 329SWILL relies entirely upon non-blocking I/O with timeouts. This 330prevents the server from indefinitely blocking the application in the 331event of bad connections and missing data. For instance, 332if a connection is made, but no HTTP headers are received, SWILL 333automatically closes the connection after a timeout and returns. 334The timeout is 335fully configurable by the user and can be set to only a few seconds if 336desired. 337 338The I/O for handler functions relies upon a temporary file created 339with {\tt tmpfile()}. When requests are serviced by handler 340functions, output is placed into this file. When a handler function 341has finished execution, the file contents along with HTTP headers are 342sent back to the client. Normally, SWILL simply passes a corresponding 343{\tt FILE *} object to handler functions so that they can perform I/O. 344As an optional feature, SWILL can also capture standard output. 345This is enabled in {\tt swill\_handle()} by prefixing the document name 346with {\tt stdout:} as follows: 347 348\begin{verbatim} 349swill_handle("stdout:foo.html",foo,0); 350\end{verbatim} 351 352In this case, all I/O operations on {\tt stdout} are captured for the duration 353of the handler function. This capture is sufficiently powerful to allow 354other programs to be executed using {\tt system()} and to have the output 355of those programs redicted to a web page. For example, the following handler 356function would capture the output of a system command: 357 358\begin{verbatim} 359void listfiles() { 360 system("ls -l"); 361} 362... 363swill_handle("stdout:files.txt",listfiles,0); 364\end{verbatim} 365 366\section{Security and Reliability} 367 368SWILL is not appropriate for use in applications that require a high 369degree of security since no support for SSL or cryptographically 370secure user authentication is provided. However, the library does 371provide a few simple security features to restrict access. First, 372basic HTTP user authentication is available by registering names and 373passwords like this: 374 375\begin{verbatim} 376swill_user("dave","iluvschlitz") 377\end{verbatim} 378 379Second, IP filters can be used to disallow or allow connections from 380specific IPs or ranges of IPs. For example: 381 382\begin{verbatim} 383swill_allow("127.0.0.0"); 384swill_deny("128.135.11."); 385swill_deny("128.135.11.8"); 386swill_deny(""); 387\end{verbatim} 388 389SWILL also allows users to register a log file in which requests will 390be recorded and which can be monitored to check for suspicious 391activity. 392 393Due to the lack of concurrency, a SWILL application may be vulnerable 394to a denial of service attack. 395However the library does take reasonable precautions to allow an application to make progress. 396As mentioned in the previous section, all I/O operations involve 397non-blocking system calls with timeouts. Therefore, it is not 398possible for a client to indefinitely block execution by keeping the 399connection open without transmitting any data. SWILL is also quick to close 400connections if it detects malformed data such as bad HTTP headers or garbled 401input. We have considered the possibility of automatically blocking 402IP addresses that repeatedly send bad requests. 403However, this is not implemented 404at this time. Given that IP filters can be used to block access, a user 405already has the means to restrict access to a set of known hosts. 406 407Finally, since SWILL is embedded in an application, it is certainly 408possible for bad programming to break the server. For instance, a 409poorly written handler function could enter an infinite loop or start 410a computation that exceeds available machine resources. In this case, 411the application would become unresponsive and would probably die. 412SWILL does not take any steps to prevent such problems. However, these 413can be anticipated with a certain amount of common sense, error 414checking, and having an understanding of the underlying 415execution model of the application. 416 417\section{Parallelized SWILL} 418 419A very useful feature of SWILL is that it supports SPMD-style parallel 420applications that utilize MPI (MPICH is currently supported) 421\cite{mpich}. This allows it to be used on Beowulf clusters and large 422parallel machines. If used in this style, every node calls {\tt 423swill\_poll()} in parallel which results in a global synchronization. 424If an incoming request is received, it is forwarded to all of the 425nodes which then execute the handler function in parallel. 426 427Using SWILL in this setting is no more difficult than in the single 428processor setting; the HTTP client connects to the master node of the 429computation, issues a request and receives sorted output collected 430from all nodes. Under the hood the implementation is also quite 431simple. The master node ({\tt MPI\_Rank $==$ 0}) 432receives requests and broadcasts them to all of the other nodes. 433Each node runs the handler function in parallel after which 434the content is collected by the master node and served in a coherent 435manner to the HTTP client. 436 437In parallel scientific programming performance is the foremost consideration. 438To evaluate the performance of {\tt swill\_poll()} we distinguish three cases: a) the case in 439which there is no pending HTTP request, b) the case where there is a 440pending request for a file or authentication, and c) the case where 441there is a request for dynamic content. 442\begin{itemize} 443{\item[a)] 444This case is quite simple. If there is no pending HTTP request, the 445master node communicates a null request to all nodes, and the host 446code continues execution immediately after the call to {\tt 447swill\_poll()}. There is one synchronization in this case, for the call 448to broadcast the null request. 449} 450{\item[b)] 451This case is also handled with an overhead of one 452synchronization. The master node identifies the pending request as one 453that can be served by it alone, serves it and broadcasts a null 454request. 455This also reveals one of our underlying assumptions, namely that the SPMD 456program is running on a shared 457filesystem of some sort, so that it would make no sense to return {\em 458n} (for {\em n} nodes) copies of the requested file. This behavior is 459easy to get around. If it is desirable that a copy of the requested 460file be returned from {\em each} node, the user can just write a 461function that reads the file in and prints it to stdout or uses {\tt 462swill\_printf()}. 463} 464{\item[c)] 465This is a somewhat more expensive operation. 466The master node broadcasts the pending request to all 467nodes, who parse it and execute the appropriate function. Then each 468node transmits the result of its execution to the master. Next, the 469master node serves the HTTP response and resumes execution of the host 470code, while the back-end nodes resume computation immediately. 471All in all, this case has a cost of one broadcast plus {\em 472n} (for {\em n} nodes) communications. 473} 474\end{itemize} 475 476In our quest for simplicity we have left it up to the 477user to produce output that denotes what process each segment of the 478output is coming from -- SWILL merely orders it in rank order and 479serves it. 480 481One interesting use of the parallel capability of SWILL is in overcoming 482limitations -- whether due to architecture or policy -- imposed by the 483administrators of clusters and supercomputing centers. Often it is 484not possible to access the backend computational nodes of a 485supercomputer or cluster in order to query the state of one's 486execution -- at least not through a normal shell. When an application 487embeds a web server, all that is required is knowledge of the master 488node and access to an unprivileged port. Web requests can then be 489easily translated into operations that execute on each node of the system. 490 491\section{Applications} 492 493SWILL has primarily been developed as a tool for remote process monitoring, 494debugging, and diagnostics. This section describes some applications in 495which we are using the library. 496 497\subsection{Scientific simulation monitoring} 498 499The motivating application for most of SWILL's development has been 500that of monitoring long-running scientific simulations. These 501programs are typically non-interactive batch jobs that provide little 502in the way of user feedback. However, to make sure a program is running 503correctly, a scientist may want to periodically monitor the state of 504their programs. For example, they might want to check for numerical 505instabilities or to see how far an experiment has progressed. 506 507To do this, a simulation can be modified slightly by implementing a few handler 508functions and inserting {\tt swill\_poll()} calls into selected places 509in the simulation loop. For example: 510 511\begin{verbatim} 512/* Initialize SWILL */ 513swill_init(3737); 514/* Register a few handlers */ 515swill_handle(...); 516swill_handle(...); 517... 518 519for (i = 0; i < nsteps; i++) { 520 compute_forces(); 521 integrate(); 522 boundary_conditions(); 523 redistribute_data(); 524 if (!(i % output_freq)) { 525 write_output(); 526 } 527 /* Check for connections */ 528 swill_poll(); 529} 530\end{verbatim} 531 532Although this is only a simple example, this technique is easily extended 533to provide a variety of advanced monitoring capabilities. For 534instance, if a graphics library is available, the web interface can be 535used to generate on-the-fly plotting and data visualization. Web access 536can also be provided to temporary files and other debugging output as 537the simulation runs. Using HTTP query variables and forms, a 538scientist could even alter various simulation parameters, enable 539diagnostic features, temporarily suspend computation, and so forth. 540 541\subsection{Compiler parse tree browsing} 542 543 544\begin{figure*}[t] 545\begin{picture}(400,380)(0,0) 546\put(30,-90){\special{psfile = swig.ps hscale = 70 vscale = 70}} 547\end{picture} 548\caption{Parse-tree browsing in SWIG} 549\label{swig} 550\end{figure*} 551 552As a more unusual example, we have used SWILL to provide a web 553interface to SWIG, a compiler for creating scripting language 554extensions \cite{swig}. One of the challenges of compiler 555implementation is that of creating, traversing, and managing parse 556tree data. For the purposes of debugging, it is fairly common to dump 557the parse tree into a text file where it can be examined. 558Unfortunately, even for small input files, this might generate a lot 559of output since a parse tree might contain hundreds to thousands of 560nodes. This makes it difficult to find the specific information of 561interest. 562 563As an alternative to dumping the parse tree to a file, a more convenient way 564to examine the parse tree data is to run SWIG using a special {\tt -browse} 565option like this: 566 567\begin{verbatim} 568$ swig -browse -c++ -python example.i 569SWIG: Tree browser listening on port 4908 570\end{verbatim} 571 572\noindent 573In this mode, the compiler enters a web-server mode after all parsing and code generation 574stages have been completed. Then, by pointing a browser at the appropriate port number, it is 575possible to point-and-click through internal parse tree data. A sample screenshot of this 576interface is shown in Figure \ref{swig}. Unlike the information in a text dump, 577the web interface provides a more more detailed picture of how information is organized in the 578compiler. For instances, pointers are represented by hyperlinks and clicking on a link is 579essentially the same as dereferencing a pointer in C. The web interface also provides 580access to compiler symbol tables, type tables, and other information. 581 582At first glance, the idea of a web-enabled compiler sounds crazy. 583However, this capability greatly simplifies debugging and development 584of the compiler. Furthermore, a web browser interface works perfectly 585well as a simple data exploration tool and it was extremely easy to 586implement---requiring only a half day of effort and a few hundred 587lines of code. In comparison, the development of a customized tree 588browser using a GUI toolkit such as Tcl/Tk would have been a much more 589involved project, would have greatly complicated the configuration of 590the compiler, and would have provided little if any extra 591functionality. 592 593\subsection{Operating systems project} 594 595At the University of Chicago, the course in operating systems requires 596students to implement a simple Unix-based kernel that runs within an 597emulated hardware environment. For emulation, we use a modified 598version of Yalnix, an emulator originally developed by Dave Johnson at 599Rice University \cite{yalnix}. 600In this project, students are given eight 601weeks to implement a kernel from scratch including boot loading, 602virtual memory management, I/O device drivers, processes, and 603interprocess communication. Kernels are implemented in C and 604typically consist of a few thousand lines of code. 605 606One of the problems of working with the emulator is that debugging is 607extremely difficult. For the most part, the only available 608diagnostics are an optional hardware trace file and the output 609of print statements included in the student's implementation. 610Unfortunately, this information is often incomplete--making it very 611difficult to reconstruct the system state that might be the source of 612a problem. 613 614As an experiment, we have recently used SWILL to add a web-interface to the 615Yalnix emulator. Internally, Yalnix relies heavily on advanced 616features of signal handling on Solaris. Specifically, user-mode 617programs execute natively on the SPARC whereas the student kernel runs 618in response to signals such as {\tt SIGSEGV} and {\tt SIGALRM} (which 619are transformed into ``hardware interrupts''). To instrument the emulator with 620a web server, we implemented a number of handler functions, 621initialized the server on startup, and placed a {\tt swill\_poll()} 622call into the {\tt SIGALRM} handler that is used for internal timing of the emulator. 623 624Using the web interface, it is possible to directly connect to the 625emulated hardware. Available information includes the current status 626of all hardware registers, page table settings, and the contents of 627physical memory pages. It is also possible to pause execution and to 628obtain traces of recent hardware operations (the history of memory 629mapped I/O ports, registers, and interrupts). More importantly, the 630web interface allows you to observe system behavior that is nearly 631impossible to obtain otherwise. For instance, by watching page tables 632you can easily spot kernel memory leaks and other inefficiencies in 633the implementation. 634 635\section{Discussion of Related Work} 636 637Internet programming is obviously a huge topic, making a detailed 638comparison of SWILL to related work difficult. Overall, we feel that 639SWILL differs from other work in a number of respects. First, a 640considerable amount of attention has been given to programming 641techniques such as CGI scripting, web server modules, server pages, 642and programming environments for building Internet applications 643\cite{cgi,apache, csp, hsp, zope}. Although these techniques are successfully 644used to incorporate programming libraries and other applications into 645a larger Internet framework, SWILL has a somewhat different focus than 646this. Instead of trying to build Internet applications, SWILL is 647mostly concerned with providing Internet access. This may be a subtle 648point, but the applications for which SWILL is the most useful are not really 649designed for the Internet---Internet access is merely an add-on feature that 650can enhance them. 651 652SWILL might also be compared to work in distributed 653computing. For instance, SOAP and XML-RPC are often mentioned as 654mechanisms for adding internet access to applications \cite{soap,xmlrpc}. 655In fact, toolkits such as gSOAP can be used to simplify the 656integration of an application into such an environment \cite{gsoap}. 657The problem with these approaches is that they are mostly focused on 658the problem of turning an application into some sort of pluggable 659network service to be used within a complicated middleware layer. SWILL, 660on the other hand, is much more lightweight and is oriented more towards 661end-users. For instance, users merely connect to the server and 662are presented with application-specific information in a format that is 663easy to use and manipulate. There is no hidden application framework 664or network layer at work. 665 666Finally, SWILL is closely related to domain-specific efforts in 667providing remote access to applications. For instance, in scientific 668computing, a lot of attention has been given to the area of 669``computational steering'' \cite{vetter2}. 670One of the primary goals 671of steering research is to provide fine-grained interactivity and user 672feedback to scientific software that is normally 673batched-oriented and non-interactive. Traditionally, this work has 674relied upon customized network protocols, complicated client 675software, and high-end hardware such as graphics workstations. 676(For a detailed discussion of computational steering we refer the reader to the excellent article \cite{vetter}.) 677 678In some cases, application frameworks 679may provide web access for this purpose. The Cactus code \cite{cactus, 680cactuspaper}, a modular scientific programming framework, is 681such an example (the CactusConnect/HTTP and CactusConnect/HTTPExtra ``thorns'' -- modules -- 682 are supposed to provide HTTP access to a cactus application). In such cases, 683however, the web 684access features are not usable as a stand-alone library. If one wants to have 685web access, one is forced to buy into a framework with all the pain and risks 686that entails. SWILL tries to avoid this by focusing 687exclusively on the problem of web access. 688 689\section{Implementation Details} 690 691SWILL is implemented entirely in ANSI C and consists of about 2500 692semicolons. Most of the implementation (1500 semicolons) simply provides a small set of 693generic data structures (hashes, lists, strings, etc.) that are used elsewhere. 694The library itself requires minimal memory overhead. 695However, all of the generated web pages involve internal buffering. 696Therefore, memory use is directly proportional to the size of 697generated web pages. Clearly the library would be inappropriate for 698serving huge amounts of data. However, this was not a design goal. 699 700The performance overhead of using SWILL depends on frequency of 701polling (and obviously the number of incoming connections). On a 702single CPU, {\tt swill\_poll()} is nothing more than a thin wrapper 703around the {\tt select()} system call. With MPI, polling requires a 704barrier synchronization across processors. This is obviously more 705expensive and careful consideration must be given to parallel 706applications. 707 708For networking, SWILL relies upon the HTTP/1.0 protocol. Although this is 709less powerful than HTTP/1.1, it is easier to implement and perfectly 710well suited for most situations. 711 712\section{Limitations} 713 714SWILL was primarily designed as a tool for building quick-and-easy web 715interfaces to C/C++ programs. Its single threaded execution would be 716inappropriate for a high-traffic web site and you probably would not 717want to use it as the basis of a large internet application. 718Similarly, internal buffering and other aspects of the implementation 719make the server inappropriate for delivering very large amounts of 720data. The server is also unable to support data streaming or any sort 721of application in which the HTTP connection would be kept alive over a 722prolonged period. 723 724Although SWILL provides some basic security mechanisms, it would not 725be appropriate for applications in which security was critical. It 726should also be added that firewalls and other security mechanisms may 727prevent users from accessing a server if access to user TCP ports is 728blocked. Obviously, SWILL cannot address these problems of social 729engineering. 730 731\section{Future Plans} 732 733In our own work, SWILL has proven to be remarkably simple and 734effective to use. Therefore, we have every intention of preserving the minimal 735nature of the implementation. However, it may be interesting to provide 736alternative interfaces to C++ and Fortran. Since SWILL does 737not rely upon anything more than a few simple functions and standard I/O operations, 738it would be relatively easy to implement handler functions with a slightly 739different calling convention. For example, in C++, SWILL might encapsulate I/O 740in an iostream object instead of a {\tt FILE *}. 741 742We have also considered the idea of allowing each SWILL-server to 743``phone home'' to a user-defined master server. If a user was running 744many different web-enabled applications, this scheme might make it 745easier to keep track of where they are running. For example, a user 746could simply connect to the master server and jump to a specific 747application from there. 748 749Obvious improvements could be made to the underlying HTTP protocol such as support 750for HTTP/1.1, secure sockets, and digest-based user authentication. However, 751supporting such features would introduce a lot of extra complexity and would probably 752offer only marginal benefits in return. 753 754\section{Availability} 755 756SWILL is freely available under a LGPL licence. More information is available at: 757 758\begin{center} 759{\tt http://systems.cs.uchicago.edu/swill} 760\end{center} 761 762\section{Acknowledgments} 763 764We would like to thank the reviewers for their helpful comments. Mike Sliczniak and Hasan Baran Kovuk 765contributed to early parts of the SWILL implementation. 766 767\begin{thebibliography}{99} 768\bibitem{beazley1} D.M.~Beazley and P.S.~Lomdahl, {\em Controlling the Data Glut in Large-Scale Molecular Dynamics Simulations}, Computers in Physics, Vol. 11, No. 3. (1997), p. 230-238. 769 770\bibitem{swig} D.M.~Beazley, {\em SWIG: An Easy to Use Tool for Integrating Scripting Languages with C and C++}, 4th Annual Tcl/Tk Workshop, Monterey, CA (1996). 771 772\bibitem{apache} Apache Web Server, {\tt http://www.apache.org}. 773 774\bibitem{zope} Zope, {\tt http://www.zope.org}. 775 776\bibitem{soap} SOAP, {\tt http://www.w3.org/TR/SOAP/}. 777 778\bibitem{gd} GD, {\tt http://www.boutell.com/gd/}. 779 780\bibitem{xmlrpc} XML-RPC, {\tt http://www.xmlrpc.com}. 781 782\bibitem{csp} C Server Pages,\\ 783 {\tt http://tesitra.com/cserverpages}. 784 785\bibitem{cgi} S.~Gundavaram, {\em CGI Programming}, O'Reilly \& Associates Inc., (1996). 786 787\bibitem{yalnix} Yalnix placeholder (we have contacted Dave Johnson, the author, about a citation). 788 789\bibitem{cactuspaper} G.~Allen et. al., {\em Supporting Efficient Execution in Heterogeneous Distributed Computing Environments with Cactus and Globus}, Supercomputing, Denver, CO, (2001). 790 791\bibitem{cactus} Cactus Code, {\tt http://www.cactuscode.org}. 792 793\bibitem{hsp} E.~Meijer and D.~van~Velzen,{\em Haskell Server Pages: Functional Programming and the Battle for the Middle Tier}, Proc. Haskell Workshop, (2000). 794 795\bibitem{vetter} W.~Gu, J.~Vetter, K. Schwan. {\em Computational steering 796annotated bibliography}, Sigplan notices, 32 (6): 40-4, (1997). 797 798\bibitem {gsoap} R.A.~van~Engelen, K.A.~Gallivan, {\em The gSOAP Toolkit for Web Services and Peer-to-Peer Networks}, Proc. IEEE CC Grid Conf., (2002). 799 800\bibitem{mpich} W.~Gropp, E.~Lusk, A~Skellum, {\em Using MPI: Portable Parallel Programming with the Message-Passing Interface}, MIT Press, (1999). 801 802\bibitem{vetter2} J.~Vetter, K.~Schwan, {\em High Performance Computational 803Steering of Physical Simulations}, Proc. Int'l Parallel Processing Symp., 804Geneva, pp. 128-132, (1997). 805 806\end{thebibliography} 807 808\end{document} 809