📄 commoncpp2.texi
字号:
\input texinfo @c -*-texinfo-*-@c %** start of header@setfilename commoncpp2.info@settitle GNU Common C++ 2@afourpaper@setchapternewpage odd@documentlanguage en@documentencoding ISO-8859-1@c %** end of header@set EDITION 1.0pre0@set VERSION 1.0@set UPDATED September 2002@dircategory Development@direntry* GNU Common C++ 2: (commoncpp2). GNU Common C++ 2 Framework Documentation.@end direntry@c -----------------------------------------------------------------------@c %** start of summary description and copyright@ifnottexGNU Common C++ 2 is the second major release of a C++ frameworkoffering portable support for threading, sockets, file access,daemons, persistence, serial I/O, XML parsing, and system services,initially started by David Sugar and Daniel Silverstone.Copyright @copyright{} 1999, 2000, 2001, 2002 Open Source Telecom Corporation.@include fdlnotice.texi@end ifnottex@c %** end of summary description and copyright@c -----------------------------------------------------------------------@c %** start of title and copyright page@shorttitlepage @titlefont{GNU Common C++ 2}@titlepage@sp 10@title GNU Common C++ 2@subtitle @subtitle @value{EDITION}th Edition, covering GNU Common C++ version @value{VERSION}@subtitle @value{UPDATED}@author David Sugar wrote this document.@author Federico Montesino Pouzols updated and formatted it in @TeX{}Info@page@vskip 0pt plus 1filll@center{Copyright @copyright{} 1999, 2000, 2001, 2002 Open Source Telecom Corporation}@include fdlnotice.texi@page@end titlepage@c %** end of title and copyright page@c -----------------------------------------------------------------------@c %** start of top node and master menu@ifnottex@node Top@topThis document describes GNU Common C++ 2, the second major release ofa C++ framework offering portable support for threading, sockets, fileaccess, daemons, persistence, serial I/O, XML parsing, and systemservices, initially started by David Sugar and Daniel Silverstone.This is the edition @value{EDITION} of this manual and documentsGNU Common C++ 2 version @value{VERSION}.@end ifnottex@contents@menu* Introduction:: What GNU Common C++ and this manual are.* Distribution:: How to get GNU Common C++.* Framework Description:: GNU Common C++ classes.* Extras:: GNU Common C++ extras.* Serverlets:: GNU Common C++ serverlets.* Compiler Options:: Compiler options to use with GNU Common C++.* Automake Services:: GNU Common C++ automake services.* Configuring Sources:: Configuring GNU Common C++ sources.* Developer Documentation:: Information of interest for CC++ developers.* Licenses:: Library and documentation licenses.* Class and Data Type Index:: Index of Common C++ classes and data types.* Method and Function Index:: Index of Common C++ methods and functions.* Concept Index:: Index of concepts.@end menu@c %** end of top node and master menu@c -----------------------------------------------------------------------@c %** start of body@node Introduction@comment node-name, next, previous, up@chapter Introduction@cindex Introduction@quotation@strong{PLEASE NOTE;} This is a preliminary version of thisdocument. Some information may not be complete or even somewhatobsolete; bug reports, suggestions and contributions are welcome.@end quotation@cindex reference manualIn writing this document I hope to better explain what the GNU CommonC++ library is about and how it may be used in developing your own C++applications. This document is intended as an overview and unifyingdocument to support the already detailed class-by-class functiondescriptions found and browsable in the "doc" subdirectory of theCommon C++ distribution.GNU Common C++ offers a set of "portable" classes that can be used to build highly portable applications in C++. In particular, Common C++ offers classes that abstract threading, sockets, synchronization, serial I/O, "config" file parsing, class object persistence, shared object moduleloading, daemon management, and optimized "block" and memory mapped fileI/O under a set of consistent classes that your application can thenbe built from. The goal is to write your application to use the portableabstract services and classes of the GNU Common C++ libraries rather thanhaving to access low level system services directly.There is a large diversity of views in how one should code a C++framework. Since a large number of older C++ compilers remain ineveryday use, I choose to use what I felt was an appropriate set ofC++ language features and practices to provide the greatest compilercompatibility and to generate the most optimized code for GNU CommonC++. To further reduce the overhead of writing GNU Common C++applications, I have split the primary library image itself intoseveral different shared libraries. This allowed me to collect themore obscure and less likely to be used features into separatelibraries which need never be loaded.Finally, in designing GNU Common C++, I assume that class extension(inheritance) is the primary vehicle for application development. The GNU Common C++ framework, while offering many classes that are usabledirectly, is designed for one to create applications by extending CommonC++ "base" classes into an application specific versions of said classesas needed. @c -----------------------------------------------------------------------@node Distribution@chapter Distribution@cindex distribution@cindex free software@cindex GNU GPL@cindex linking exception@cindex GNU FDL@cindex philosophyThis manual is licensed under the terms of the @acronym{GNU} FreeDocumentation License, @xref{GNU Free Documentation License}.@acronym{GNU} Common C++ is free software (see@url{http://www.gnu.org/philosophy/philosophy.html}). There areseveral ways to get @acronym{GNU} Common C++, refer to@url{http://www.gnu.org} and@url{http://www.gnu.org/software/commoncpp/}.The @acronym{GNU} Common C++ framework is licensed under the terms ofthe @acronym{GNU} General Public License, @xref{GNU General PublicLicense}, plus a linking exception, @xref{GNU Common C++ LinkingException}, that grants additional privileges. These privileges aresimilar to the terms Guile is licensed under and constitute privilegessimilar to the LGPL. David Sugar explains why these licensing termswere chosen for Common C++ as follows:The one problem I recall immediately with the LGPL as it applies toC++ class frameworks is the way it defines and refers to ``linking''vs ``derived works''. In concept, a C++ header with inline members ortemplate is not ``linked'' in the same sense as one might presume themeaning in traditional C library, and what does one make of a classwho's base class is defined in a header in a LGPL protected library?Is creating a derived C++ class purely a linking operation or creatinga derived/composite work?At the time it seemed simpler to take the language of the GPL andprovide an appropriate privileges to allow Common C++ to be used inways that achieve the same goals of the LGPL, but without using thesame choice of language for this that is found in the LGPL. Weactually looked at the Guile license, which also faced many of thesequestions, and choose to use their methodology for creating a specialprivilege in this regard. Of course, this was a number of years ago,and the language of the LGPL (and GPL) has evolved over time to betteraddress the needs of object oriented frameworks. If the language ofthe current LGPL were close enough to resolving these goals, I thinkwe would likely switch to it, as that would resolve some confusionover the exact license status. I have found it simpler to explain itas a LGPL-like license since we were trying for much the same effectwithin the context of a C++ framework, and most people basicallyunderstand what the LGPL is.@c -----------------------------------------------------------------------@node Framework Description@chapter Framework Description@cindex Framework DescriptionThis chapter provides a description of the GNU Common C++ frameworkmain components.@menu* Overall Concepts:: Global GNU Common C++ Practices.* Threading Concepts:: GNU Common C++ Threading Concepts.* Synchronization:: GNU Common C++ Synchronization.* Sockets:: GNU Common C++ Sockets.* Serial I/O:: GNU Common C++ Serial I/O.* Block I/O:: GNU Common C++ Block I/O.* Daemons:: GNU Common C++ Daemon Support.* Persistence:: GNU Common C++ Persistence.* Configuration and Misc.:: GNU Common C++ Configuration and Other Things.* Numbers and Dates:: GNU Common C++ Numbers and Dates Manipulation.* URL Streams:: GNU Common C++ HTTP Support.* XML Streams and RPC:: GNU Common C++ XML Streams and RPC.* Exceptions:: GNU Common C++ Exception Model.* Templates:: GNU Common C++ Template Subsystem@end menu@c -----------------------------------------------------------------------@node Overall Concepts@section Overall Concepts @cindex Overall Concepts@cindex ost@cindex ost namespace@cindex namespaceUnless explicitly stated, all GNU Common C++ symbols are under the@code{ost} namespace@footnote{Provided the C++ compiler used tocompile GNU Common C++ suupports namespaces, which is checked atconfiguration time.}. Thus, when we refer to the Thread class, weactually refer to ost::Thread.The GNU Common C++ framework actually consists of two libraries:@file{ccgnu2} and @file{ccext2}@footnote{@xref{Compiler Options}, forhow to specify compiling and linking options for these libraries. OnWin32 systems, these libraries are compiled as @file{ccgnu2.dll} and@file{ccext2.dll}}. The first includes core functionality that otherthings commonly depend on, such as threading and synchronization. Thatway, if you are building a tight application with a small footprint,you can have it used the ccgnu2 shared image alone. On the contrary,things that require or induce new library link requirements areincluded in @file{ccext2}. Hence, for example, if you do not wish touse XML parsing in your application, why create an unused librarydependency for libxml2? The idea being that one can, if one needs to,use only ``core'' features found in ccgnu2 and then create verycompact executables with very few additional library dependencies.@c -----------------------------------------------------------------------@node Threading Concepts@section Threading Concepts @cindex Threading Concepts@cindex threading@cindex APE@cindex Java threadingThreading was the first part of GNU Common C++ I wrote, back when itwas still the APE library. My goal for GNU Common C++ threading hasbeen to make threading as natural and easy to use in C++ applicationdevelopment as threading is in Java. With this said, one does notneed to use threading at all to take advantage of GNU Common C++.However, all GNU Common C++ classes are designed at least to bethread-aware/thread-safe as appropriate and necessary.@cindex pthread@cindex ost_pthread.m4@cindex autoconfGNU Common C++ threading is currently built either from the Posix"pthread" library or using the win32 SDK. In that the Posix "pthread"draft has gone through many revisions, and many system implementationsare only marginally compliant, and even then usually in differentways, I wrote a large series of autoconf macros found inost_pthread.m4 which handle the task of identifying which pthreadfeatures and capabilities your target platform supports. In theprocess I learned much about what autoconf can and cannot do foryou.@cindex GNU pth@cindex pthCurrently the GNU Portable Thread library (GNU pth) is not directlysupported in GNU Common C++. While GNU "Pth" doesn't offer directnative threading support or benefit from SMP hardware, many of thedesign advantages of threading can be gained from it's use, and thePth pthread "emulation" library should be usable with GNU Common C++.In the future, GNU Common C++ will directly support Pth, as well asOS/2 and BeOS native threading API's.@cindex threading modelGNU Common C++ itself defines a fairly "neutral" threading model thatis not tied to any specific API such as pthread, win32, etc. Thisneutral thread model is contained in a series of classes which handlethreading and synchronization and which may be used together to buildreliable threaded applications.@tindex Thread@findex Thread::run@cindex execution context@cindex termination@cindex thread terminationGNU Common C++ defines application specific threads as objects whichare derived from the GNU Common C++ "Thread" base class. At minimumthe "run" method must be implemented, and this method essentially isthe "thread", for it is executed within the execution context of thethread, and when the run method terminates the thread is assumed tohave terminated.@cindex priority@cindex thread priorityGNU Common C++ allows one to specify the running priority of a newly created thread relative to the "parent" thread which is the thread that isexecuting when the constructor is called. Since most newer C++implementations do not allow one to call virtual constructors or virtualmethods from constructors, the thread must be "started" after theconstructor returns. This is done either by defining a "starting"semaphore object that one or more newly created thread objects can waitupon, or by invoking an explicit "Start" member function.@cindex suspended@cindex resumed@cindex SIGUSR1@cindex SIGSTOP@cindex SIGCONT@cindex solaris threads@cindex linux threadsThreads can be "suspended" and "resumed". As this behavior is notdefined in the Posix "pthread" specification, it is often emulatedthrough signals. Typically SIGUSR1 will be used for this purpose inGNU Common C++ applications, depending in the target platform. OnLinux, since threads are indeed processes, SIGSTOP and SIGCONT can beused. On solaris, the Solaris thread library supports suspend andresume directly.@cindex cancelable threadsThreads can be canceled. Not all platforms support the concept ofexternally cancelable threads. On those platforms and APIimplementations that do not, threads are typically canceled throughthe action of a signal handler.@findex Thread::setCancellation@findex Thread::exit@findex Thread::run@cindex cancellation@cindex cancellation pointAs noted earlier, threads are considered running until the "run"method returns, or until a cancellation request is made. GNU CommonC++ threads can control how they respond to cancellation, usingsetCancellation(). Cancellation requests can be ignored, set to occuronly when a cancellation "point" has been reached in the code, oroccur immediately. Threads can also exit by returning from run() orby invoking the exit() method.@findex Thread::terminate@cindex thread initialization@cindex thread destructionGenerally it is a good practice to initialize any resources the thread
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -