On Wednesday October 19 2005 15:57, Lou wrote: > > There are some more complete examples in the src/tests subdirectory. > > Thanks. I saw them, but in my newbie state, couldn't make head or tail > of them; how I'd know whether they succeed or fail, etc. I specifically > grepped them for Bot to see if that example program was there and came > up empty. I see your point. But I hope to get rid of the example in its current form and be able to point people to the (hopefully then) more complete API docs. I don't want to copy'n'paste *to* the page either. ;) > > As Johan already pointed out, you should be able to do that without > > problems. However, there are some corner cases where appropriate locking > > is still needed in gloox. For example, there is a possible race condition > > in Client::connect() if called more than once simultaneously. > > Cool. I plan to only call Client::connect() within the spawned thread, > of which there will only be one. Actually, the only shared resource > (probably a subclass of std::queue<std::string>) will be the object that is > used to communicate with the main thread, which, will, of course, itself, > have to be threadsafe. Well, and the Client object, of course, which I > will only be calling send() on. Now that I think about it, there is another possible race condition -- in Connection::send(). If you send() from different threads at the same time there is a chance that the output at the remote end is a mixture of the input. For now, you'll have to implement some higher-level mutex around the send function to avoid that. > Oh, I may want to be sending structs containing Stanza *, etc. from the > callbacks back to the main thread (instead of std::string). Is that > going to cause a problem with destruction of the object being pointed > to, in which case, I will have to copy it first (put Stanza in the > struct instead of Stanza *)? These objects will only be read by the > main thread, and only when they are dequeued. If I understand you correctly, you'll have to clone() the Stanza in your callback thread. Stanzas you receive from the network as well as those you send() out are deleted automatically for you. The former after you return from the handler, the latter right after sending them out. Cloning was only added in 0.7-pre1 <http://camaya.net/download/gloox-0.7-pre1.tar.bz2> (and is broken there). There is a patch at <http://bondeson.mine.nu/johan/joline/fix_stanza_copy.diff> to fix that. > One more question: > Is there a way to get a file descriptor or something that I can select() > on to tell that a message has arrived? There is no such functionality. However, since somebody else already asked for this, I've put it on my todo for 0.7-final. cheers, Jakob
Attachment:
pgpGfhBFhu8Nb.pgp
Description: PGP signature
-- gloox-dev mailing list to unsubscribe: send a message with subject 'unsubscribe gloox-dev' to minimalist@xxxxxxxxxx