Mail Quotas in Mac OS X Server 10.5
Apparently Mac OS X Server 10.5 has some nasty issues in handling mail quotas. While it is possible to specify a mail quota above 2 GB for a user in the Workgroup Manager, doing so leads to nasty mail delivery problems. We just had the case here where the mail quota was set to 4 GB, yet delivery of mail messages failed despite only 28 % of that quota being used. These issues become apparent in Server Admin, when looking at Mail/Maintenance/Accounts. With a mail quota over 2 GB, strange numbers will appear in the Mail Quota column (apparently the result of an integer overflow). Interestingly, the cyrus-quota command will display the correct values, yet delivery of messages still fails. The reason is only hinted in the Mail Access log, where “Over quota” messages will appear. Messages for the respective mailbox will remain in the postfix mail queue, with a temporary failure; no warning emails will be sent. Nasty, because the only way to find out about the issue is when a user no longer receives any email messages. We have now set quotas to 2000 MB, which fixes the issues. Note that to changes to a user’s mail quota to become visible to cyrus, the user has to login to the mail server after changing the quota.
We had another issue today as well (which somehow lead to the other issue) as the cyrus mail quota handling got messed up. This is a known issue in cyrus, which can be fixed by running the cyrus-quota command, as in
sudo -u _cyrus /usr/bin/cyrus/bin/cyrus-quota -f
Hiding The GTK+/X11 Mouse Cursor
One of the recurring problems when building user interfaces for touchscreen-based devices with GTK+ on Linux is making the mouse cursor invisible. When using a touchscreen only (and no mouse), the mouse cursor is an unnecessary distraction in the user interface. You might guess that such a simple thing as to hide the mouse cursor should be quite easy. But it’s not. After doing some research I found a viable solution: set the X11 cursor theme to a 1×1 pixel transparent image for all cursors. This is what the GTK+-based Maemo versions do, for example. Here’s how to do it. First, get the cursor theme. You can get it from the Mamo osso-af-utils package. Since this package contains other things not needed here as well, I have extracted the xcursor-transparent theme into a gzipped tar file. You can get it here. Next, install the theme by unpacking the xcursor-transparent.tar.gz file in /usr/share/icons:
$ cd /usr/share/icons
$ tar xfz ~/xcursor-transparent.tar.gz
Finally, you have to make this theme the default theme. This can be done by creating (or editing) the file /usr/share/icons/default/index.theme to contain the two lines:
[icon theme]
Inherits=xcursor-transparent
After restarting the X server and your Gtk+ application, the mouse cursor will be gone. I use this together with the GTK+ WebKit port, running a WebKit view fullscreen, with the HTML served by a local POCO-based custom web server.
What A Difference A New Site Makes
This week I have updated the POCO C++ Libraries website. The site now has a completely new design that looks modern, friendly and is easy to use. To give credit where credit is due, the design was in part influenced by the design of the Ruby On Rails website. We now also have much better documentation with the addition of 23 slide decks that provide overviews, tutorials and guidance when using the libraries.
The new website has now been online for three full days, and the Google Analytics statistics look promising. The bounce rate is now down to 30 %, from 50 % previously. Pageviews are up 60 %. And we’ve got new mailing list subscribers every day.

Visits

Page Views

Bounce Rate
Reverse HTTP
In the recent days and weeks I thought about a way to use HTTP as a device management protocol, to access devices sitting behind NAT routers or firewall. The idea is, basically, to access a device’s web interface, even if the device is behind a firewall, and thus not reachable by HTTP. The basic idea I had was that the device would initiate a (secure) socket connection to a central device management server. This is usually not a problem for devices sitting behind a NAT router or firewall. That connection would then be used for HTTP – but in the reverse direction. That means, the server would use the connection established by the device to send HTTP requests to the device. There would also be a simple reflector service on the server, which would forward incoming HTTP requests for a device’s web interface to the device, over the reverse HTTP connection. So far so good. Now, I did some Googling today, and found that others have had similar ideas. There’s even an internet draft for Reverse HTTP that was submitted in March 2009. Great – this might some day even become a standard practice.
Notes on John Siracusa’s Copland 2010 Revisited
A few quick remarks on Copland 2010 revisited: Apple’s language and API future:
- Java did not became popular because it was based on a Virtual Machine. It became popular because the language was reasonably simple, and it came with a usable class library. And it was marketed heavily – thus sounding the death knell to Smalltalk, which, as I remember from back then, was on the verge of becoming popular when suddendly Java appeared on the scene*.
- .NET did not became popular because of the CLR. It was because all other technologies Microsoft had at the time (Windows API, Visual Basic, Visual C++ 6**, MFC, COM, etc.) were horrible (or close to). .NET provided easier to use languages and a usable class library, plus a good migration path.
- Apple already has a great class library — Cocoa. Probably the best GUI class library/framework that’s out there. Objective-C(++) may have some quirks, but (especially in version 2.0) is still a good language. So, Apple is in no hurry to change things. Apart from that Apple now has LLVM, which is a great foundation for future development.
* ironically, Java brought also the end to OPENSTEP, an ancestor of today’s Cocoa, which Sun had licensed from NeXT
** to be fair: most other C++ compilers at the time sucked as well…
Windows CE 6 and Visual Studio 2008 Debugging Gotchas
Getting remote debugging to work with Visual Studio 2008 and Windows Embedded CE 6 (or whatever it’s called today) can be a frustrating experience. Here are a few tips that help to avoid various gotchas.
First, if you’re going to debug with Visual Studio 2008, you’ll probably need new versions of ConManClient2.exe and cmaccept.exe, together with various DLLs, installed on your device. The versions of these tools already installed on the device are probably meant to be used with Visual Studio 2005. Visual Studio 2008 requires newer versions of these, otherwise an attempt to connect to the device will fail with an error message telling that the ConManClient2 on the device is not compatible. These files can be found in C:\Program Files\Common Files\Microsoft Shared\CoreCon\1.0\Target\wce400\<arch>. Note that you might also have a C:\Program Files\Common Files\Microsoft Shared\CoreCon\5.01\bin\target directory. However, the files from that directory won’t work. Copy them to your device (e.g., by FTP) or put them onto a USB drive. Once the files are on your device, you’ll need to start ConManClient2 and cmaccept. An older version of ConManClient2 might already be running on your device, so stop it first, by running ClientShutdown.exe. I use a script to do this:
rem StartDebug.cmd
"\Hard Disk\ClientShutDown.exe"
start "\Hard Disk\ConManClient2.exe"
echo "Press return to launch cmaccept"
time
"\Hard Disk\cmaccept.exe"
Replace “Hard Disk” with the name of the folder where the executables are located. Note the call to time — it’s only purpose is to delay starting cmaccept.exe until ConManClient2 in ready. Normally, one would use the pause command for this purpose, but, funnily, on Windows CE, pause simply writes “Press any key to continue…” and then immediately continues, without waiting for any key to be pressed… Has anyone filed a bug report on this?
Once cmaccept runs, you should be able to connect to the device, provided the device connection has been set up properly (Tools > Options > Device Tools > Devices).
Next thing you might notice is that you can start remote debugging from within Visual Studio, but your breakpoints do not work. Also, you won’t see any source code when you break execution (Debug > Break All). In this case, check your linker settings in the project properties. Make sure that under Linker > Advanced, the setting Randomized Base Address is set to Disable Image Randomization (/DYNAMICBASE:NO). Sounds logical, doesn’t it. Once you’ve found the setting.
Happy remote debugging!
How NOT To Design XML Schemas
If you are designing XML schemas, do any of the following things to make your schemas a real pain in the ass to use:
- Make sure every schema uses a different target namespace, even if all schemas contain types that are meant to be used together.
- Use the same type name for different types in different schemas (will only work if you also do 1).
- Invent your own versioning and extension mechanism for the resulting XML documents, because “must ignore” has never worked well in the history of the Web. Preferrably, create a “V2″ element (and, within that, a V3 element, etc.) to contain all elements added at later versions of the schema. Make these elements optional, so that it becomes real hard to access an element value present only in version 4 of the schema.
- Make sure to absolutely never run your schemas through a data binding code generator before you publish them, so you don’t see the ugly code that gets generated from your schema (if the data binding tool can process your schema at all).
- Ensure that all schemaLocation attributes in your import/include elements contain absolute paths or HTTP/FTP URIs, so that local fixes to your schemas will be overridden.
- Allow for unlimited extensibility by adding unbounded any elements to every sequence.
Thoughts on C++ vs. Java and .NET Performance
I recently spent some time improving the performance of my company’s Fast Infoset library. The library has been written back in 2006 and is based on the XML library from the POCO C++ Libraries.
After spending some quality time in the debugger trying to find out what actually goes on in the parser (I did not write the original code myself), the first thing I noticed was an excessive amount of memory allocation and string copying going on. So now I had something to focus on. For various reasons, I prefer to use std::string to handle strings in all of the C++ code I write. First of all, std::string is the standard string class in C++, so it’s natural to use it in all interfaces where a string has to be passed around. Otherwise you’ll end up with what I call C++ string hell, where half of your code ends up doing conversions between different string implementations. Windows C++ and COM developers know what I’m talking about. Now, std::string is a fine string class, with only two drawbacks. First, as soon as you’re going down the std::string route, there’s no way out. Mixing it with another string implementation requires string conversions, resulting in endless copying and memory allocation nightmare. This is not easily fixed, and we’ll have to live with that. The second, bigger issue, is that copying std::string objects is very expensive. Sure, some time ago we had reference counted std::string implementations that tried to avoid memory allocation and copying through the use of copy-on-write mechanisms. But these were ill-fated as well, mostly because copy-on-write had to be implemented very conservatively so that copies were in many cases created even when not necessary. Also, implementing these strings in a thread-safe way required expensive locking. So, no reference counted std::strings for us (except for those stuck with GCC 3.x or Visual C++ 6).
So, with all that in mind, I tried to reduce std::string copying and memory allocation as much as possible. What I did was reusing std::string instances as often as possible. For example, for certain temporary strings needed for various purposes, I no longer create a std::string instance on the stack, but rather use a std::string instance variable in my class. Memory for that string is allocated once (I use reserve() to preallocate sufficient memory for typical strings), thus saving many memory allocations and deallocations. For example, previously, one std::string instance was created (and destroyed) for every element found in a Fast Infoset document. Now, there’s just one std::string instance created for the whole document. Consider a large Fast Infoset document with 100000s of elements and you can imagine what this means. There were a few other changes I made to the code (reducing heap allocations in other places, improving the implementations of various tables, etc.) but nothing brought as significant performance improvements as reducing std::string memory allocations and copying.
And this is where Java and .NET have a significant performance advantage over C++ (when using std::string). Strings in Java and .NET are immutable, which means that, once a string has been created, it can no longer be modified. This has a few implications for performance. First, it is never necessary to copy strings. Strings are reference classes in .NET and Java anyway, so when passing around a string, only a pointer needs to be passed. Compare this with C++, where, unless a pointer or reference is used, the string object is actually copied, resulting in a memory allocation and memory copy operation. There are many cases where all one has to do is to store and/or pass around immutable strings. XML and Fast Infoset parsers are a prime example: element and attribute names and character data strings are created once by the parser, and then never modified again. The lack of a standard immutable string class in C++ is a real drawback here, performance wise.
Another issue where Java and .NET have performance advantages over C++ and the C++ Standard Library is streams. Streams in Java and .NET are plain simple — all they do is transport raw bytes around. There’s no encoding, no localization and no formatting, this is handled by separate classes. Compare C++ iostreams, that include reading and writing with character encoding conversion (via locales) in one class, the stream buffer (formatting and localization is handled by stream classes, on top of stream buffers). If one wants to just read or write raw bytes from/to a file, there’s some overhead involved, due to locale support, when using std::fstream (or other stream (buffer) classes that use locales). It’s possible to implement stream buffers that do not use locales, but this requires extra work (e.g., the stream and stream buffer classes in POCO).
While well written C++ code is usually faster than equivalent Java or .NET code, some extra work (and good knowledge of the standard library internals) is required to write fast C++ applications dealing with lots of strings or stream-based I/O.
Samsung Bada
Samsung has released a new OS/platform for smartphones, based on C++. My initial excitement for the platform has vanished quickly, though, after looking at their introductory presentation for developers. First thing that caught my eye was “two-phase construction”. That immediately rang my alarm bells. This was followed by their explanation that one cannot use C++ exceptions due to “resource constraints” on embedded devices. Instead, one has to use a home-grown macro-based exception handling mechanism, as well as return value error codes. Now that explains the need for two-phase construction. Note to Samsung: Symbian called – it wants its design mistakes from the 90s back. Other things that I noticed were a lack of smart pointer usage (apparently, smart pointers are too resource hungry, or what) and a few other things that should send shivers down the spine of any C++ developer. And they have Java-like container classes as well. So, unfortunately, nothing to get excited about. Looks like iPhone, Symbian 9.x and Linux-based platforms like Maemo remain the only choices for C++ developers.
New Case Study on my Company Website
Read my company’s new case study to learn how the C++ libraries and tools from Applied Informatics helped building an innovative ticketing/admission control unit.