[erlang-questions] Newbie - eldap and threads

Chandru chandrashekhar.mullaparthi@REDACTED
Thu Feb 18 18:10:53 CET 2010


On 18 February 2010 08:21, Humaira Surve <humaira.surve@REDACTED> wrote:
> Hi,
> I've recently began playing around with erlang and come from a java
> background.
> I was quite impressed by the eldap library and its general simplicity to
> use. I have a question though.
> If one opens a single connection and binds, but has multiple clients sending
> requests through this one connection,
> is there a possiblity of thread-related issues.

Not really. All requests are multiplexed on to the same connection.

> What guarantees that a client gets the correct response or that a response
> is not over-written by more than one simultaneous request?
> I have looked through the eldap code and noticed that a single connection
> uses a TCP file descriptor.

See the source in eldap_fsm:send_command/3. I've added comments.

send_command(Command, From, S) ->
    %% Assign a unique id for this request which is the messageID in
the LDAP request
    Id = bump_id(S),

   %% Build the request
    {Name, Request} = gen_req(Command),
    Message = #'LDAPMessage'{messageID  = Id,
                 protocolOp = {Name, Request}},
    log2("~p~n",[{Name, Request}], S),

    %% Do ASN.1 encoding
    {ok, Bytes} = asn1rt:encode('ELDAPv3', 'LDAPMessage', Message),

    %% Send the request on the socket
    ok = gen_tcp:send(S#eldap.fd, Bytes),

    %% Start a timer
    Timer = erlang:start_timer(?CMD_TIMEOUT, self(), {cmd_timeout, Id}),

     %% Store the mapping from unique id to 'From' which is a
reference to the calling process
    New_dict = dict:store(Id, [{Timer, From, Name}], S#eldap.dict),

    {ok, S#eldap{id = Id,
         dict = New_dict}}.

When a response is received, the LDAP server will include the
messageID in the response. The eldap_fsm process looks up its state
and retrieves the reference to the calling process (assuming the
request has not timed out), and sends the response out.  This is
handled in eldap_fsm:recvd_packet/2


More information about the erlang-questions mailing list