Re: Registering ldap connection with event loop?

Eric Rosenquist (rosenqui@strataware.com)
Mon, 15 Jul 1996 16:00:07 -0400

On 15 Jul 96 at 12:06, sbrown@ccsmtp.canon.com wrote:

> ...
> I would like to register the the file descriptor for the ldap connection
> with my X event loop so that I can then call ldap_result() when there is
> some activity.
>
> Questions:
>
> After perusing the ldap stucture I am unsure of the proper field(s) to
> use... can someone help me with that? The actual read/write socket
> description would be most helpful.
>
> Is there another/better way to do this that I have not grasped?

The only 'clean' way to do this (that I know of) is to poll the LDAP
connection in a timer event by calling:

static struct timeval nullTimeout; /* Static initialization will set this to 0s */
LDAPMessage *result = NULL;
resType = ldap_result(ld, LDAP_RES_ANY, 1, nullTimeout, &result);
if (resType == 0)
; /* Nothing available */
else if (resType == -1)
; /* Error! */
else {
/* We got a result */
}

If you want to check for a result without actually grabbing the next
result, you'll have to access the socket descriptor inside the LDAP
structure:

ld->ld_sb

which is of type Sockbuf, which under everything but the Mac has an 'int'
member with the socket descriptor, so what you want is:

ld->ld_sb.sb_sd

However, this will probably not be very reliable if you've built a 3.3
client with referrals, since chasing a referral involves binding to
another server and getting a different descriptor.

If you can manage to make the ldap_result() technique fit into your
application then it is far and away the best way, and the only really
safe way.

> In addition it would seem that a api call to get this would be benifical
> since I imagine that many client side applications will have there own
> event loops to contend with.

Handling referrals in the client has really complicated things, but yes,
some sort of API that returned an FDSET of active LDAP descriptors would
be useful in a lot of environments, and would avoid the need to regularly
poll via ldap_result().

Eric
---------------------------------------------------------------------
Eric Rosenquist, Strata Software Limited http://www.strataware.com/
Email: rosenqui@strataware.com Tel: 613-591-1922 Fax: 613-591-3485
Quote: Gentlemen, in a way you're both winners. But in another, more
accurate way, Barney is the winner.
-- NASA official to Homer and Barney
---------------------------------------------------------------------