Unix

NAVIGATION
CATEGORIES
REFERRENCE
LINKS
  • mach_msg trouble

    6 answers - 1079 bytes - related search similar search Add To My Delicious Add To My Stumble Upon Add To My Google Mark Add To My Facebook Add To My Digg Add To My Reddit

    I'm trying to set up a simple server that just receives messages
    (not threaded). So, i have written
    /* for port allocation */
    ipc_space_t ist;
    kern_return_t port_err;
    mach_port_t name;
    task_t self;
    /* for message reception */
    mach_msg_return_t msg_err;
    mach_msg_header_t msg_body;
    port_err=mach_port_allocate(mach_task_self(),
    MACH_PRT_RIGHT_RECEIVE, &name);
    if (port_err!=KERN_SUCCESS)
    error(1, port_err, "cannot allocate port, %d", port_err);
    msg_err=mach_msg(&msg_body, MACH_RCV_MSG, 0, sizeof(msg_body),
    XXX,
    MACH_MSG_TIMEUT_NNE,
    MACH_PRT_NULL);
    if (msg_err!=MACH_MSG_SUCCESS)
    error(1, msg_err, "error receiving message, %d", msg_err);
    I don't know what to put instead of XXX to make this task
    reveive messages at the allocated port.
    Secondly, how can a client discover this server's port in order to
    send something?
    Any help is appreciated!
    Thanks,
    Constantine
    Bug-hurd mailing list
    Bug-hurd (AT) gnu (DOT) org
  • No.1 | | 1346 bytes | |

    Constantine Kousoulos wrote:

    port_err=mach_port_allocate(mach_task_self(),
    MACH_PRT_RIGHT_RECEIVE, &name);
    if (port_err!=KERN_SUCCESS)
    error(1, port_err, "cannot allocate port, %d", port_err);

    msg_err=mach_msg(&msg_body, MACH_RCV_MSG, 0, sizeof(msg_body),
    XXX,
    MACH_MSG_TIMEUT_NNE,
    MACH_PRT_NULL);
    if (msg_err!=MACH_MSG_SUCCESS)
    error(1, msg_err, "error receiving message, %d", msg_err);

    I don't know what to put instead of XXX to make this task
    reveive messages at the allocated port.

    I bypassed the previous problem using

    mach_port_t rcv = mach_reply_port();
    msg_err=mach_msg(&header, MACH_RCV_MSG, 0, sizeof(header),
    rcv,
    MACH_MSG_TIMEUT_NNE,
    MACH_PRT_NULL);

    Secondly, how can a client discover this server's port in order to send
    something?

    Let me explain a bit more and correct me if i am wrong. In order
    for two threads to communicate via mach_msg(), those two threads
    must belong to the same task. In order for a client program to
    communicate with an entirely different server program, mig or
    sockets are needed. When mig is used, how can i bind my server
    program to a specific port to listen for messages?

    Thanks in any case,
    Constantine

    Bug-hurd mailing list
    Bug-hurd (AT) gnu (DOT) org
  • No.2 | | 1890 bytes | |

    Sat, Nov 25, 2006 at 10:32:17AM +0200, Constantine Kousoulos wrote:
    I bypassed the previous problem using

    mach_port_t rcv = mach_reply_port();
    msg_err=mach_msg(&header, MACH_RCV_MSG, 0, sizeof(header),
    rcv,
    MACH_MSG_TIMEUT_NNE,
    MACH_PRT_NULL);

    >Secondly, how can a client discover this server's port in order to send
    >something?


    Let me explain a bit more and correct me if i am wrong. In order
    for two threads to communicate via mach_msg(), those two threads
    must belong to the same task. In order for a client program to
    communicate with an entirely different server program, mig or
    sockets are needed. When mig is used, how can i bind my server
    program to a specific port to listen for messages?

    Not really, no. mach_msg() is used to queue messages to ports, whether
    or not the receiver is a thread of the same task, or is associated to
    another task. Mig is just a way to create high level RPC on top of
    mach_msg().

    The problem, as you could find out, is that the sender needs to know
    where to send the message (it must acquire a send right on the receiver
    port). When using threads of the same task, this is rather easy,
    because that information is accessible by both threads (using global
    variables or pointers for example) and you don't need any kind of
    registering service. When threads are in different tasks, the problem
    is usually solved by a server dedicated to registering ports and known
    by all threads. The Hurd actually uses the file system for this (see
    the Hurd function file_name_lookup()). It's not the role of Mach to
    provide such a service.

    See http://www.update.uu.se/~ams/notes/mach-ipc-without-mig and
    http://www.update.uu.se/~ams/notes/ipc-hello.c for an example of how two
    threads can use mach_msg().
  • No.3 | | 577 bytes | |

    Richard Braun wrote:
    When threads are in different tasks, the problem
    is usually solved by a server dedicated to registering ports and known
    by all threads. The Hurd actually uses the file system for this (see
    the Hurd function file_name_lookup()). It's not the role of Mach to
    provide such a service.

    Thanks for the clarification. I was wondering if Mach kept a list
    of registered ports (with specific port rights) that different
    tasks could access.

    Constantine

    Bug-hurd mailing list
    Bug-hurd (AT) gnu (DOT) org
  • No.4 | | 461 bytes | |

    Hi,

    Thu, Nov 23, 2006 at 09:31:27PM +0200, Constantine Kousoulos wrote:
    I'm trying to set up a simple server that just receives messages (not
    threaded). So, i have written
    []

    of curiosity: Why are you working at such a low abstraction level?
    You have some specific task in mind, or just want to get idea on the
    inner workings of the Hurd?
    -antrik-

    Bug-hurd mailing list
    Bug-hurd (AT) gnu (DOT) org
  • No.5 | | 813 bytes | |

    olafBuddenhagen (AT) gmx (DOT) net wrote:
    Hi,

    Thu, Nov 23, 2006 at 09:31:27PM +0200, Constantine Kousoulos wrote:
    >I'm trying to set up a simple server that just receives messages (not
    >threaded). So, i have written

    []

    of curiosity: Why are you working at such a low abstraction level?
    You have some specific task in mind, or just want to get idea on the
    inner workings of the Hurd?

    The second.

    Now it's my turn to be curious: can i do the same things at a
    higher abstraction level? :) I didn't realise that the
    abstraction level was so low. I just try to utilise the interfaces
    that mach.texi and hurd.texi describe.

    Constantine

    Bug-hurd mailing list
    Bug-hurd (AT) gnu (DOT) org
  • No.6 | | 542 bytes | |

    Sat, Nov 25, 2006 at 05:49:07PM +0200, Constantine Kousoulos wrote:
    Now it's my turn to be curious: can i do the same things at a
    higher abstraction level? :) I didn't realise that the
    abstraction level was so low. I just try to utilise the interfaces
    that mach.texi and hurd.texi describe.

    Well yes, of course. It would be hard to build translators if using only
    the low level Mach interface. The Hurd provides libports for high level
    RPC. Check the Hurd hacking guide [1] for an example of how to use it.

Re: mach_msg trouble


max 4000 letters.
Your nickname that display:
In order to stop the spam: 5 + 4 =
QUESTION ON "Unix"

EMSDN.COM