jack1 codebase
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

145 lines
5.2KB

  1. /*
  2. Copyright © Grame 2003
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  14. Grame Research Laboratory, 9, rue du Garet 69001 Lyon - France
  15. grame@rd.grame.fr
  16. */
  17. #include "ipc.h"
  18. /*
  19. RPC without time out can put the jack server in a blocked state (waiting for the client answer) when a client is killed.
  20. The mach_msg function does not return any error in this case. Using time out solve the problem but does not seems really
  21. satisfactory.
  22. */
  23. #define WAIT 25 /* in millisecond */
  24. int
  25. jack_client_resume(jack_client_internal_t *client)
  26. {
  27. mach_msg_header_t *head = &client->message.header;
  28. int err;
  29. if (!client->running) {
  30. err = mach_msg (head, MACH_RCV_MSG, 0, sizeof(client->message), client->serverport, 0, MACH_PORT_NULL);
  31. if (err) {
  32. jack_error("jack_client_resume: priming receive error: %s\n", mach_error_string(err));
  33. return -1;
  34. }
  35. client->running = TRUE;
  36. }else {
  37. /* remote port is already the send-once he sent us */
  38. head->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_MOVE_SEND_ONCE, 0);
  39. head->msgh_local_port = MACH_PORT_NULL;
  40. head->msgh_size = sizeof(mach_msg_header_t);
  41. err = mach_msg(head, MACH_SEND_MSG|MACH_RCV_MSG|MACH_SEND_TIMEOUT|MACH_RCV_TIMEOUT,
  42. sizeof(*head), sizeof(client->message), client->serverport, WAIT, MACH_PORT_NULL);
  43. if (err) {
  44. /*
  45. switch(err) {
  46. case MACH_SEND_TIMED_OUT:
  47. jack_error("MACH_SEND_TIMED_OUT %s\n", client->control->name);
  48. break;
  49. case MACH_RCV_TIMED_OUT:
  50. jack_error("MACH_RCV_TIMED_OUT %s\n", client->control->name);
  51. break;
  52. case MACH_SEND_INVALID_DEST:
  53. jack_error("MACH_SEND_INVALID_DEST %s\n", client->control->name);
  54. break;
  55. }
  56. */
  57. jack_error("jack_client_resume: send error for %s\n", mach_error_string(err));
  58. return err;
  59. }
  60. }
  61. return 0;
  62. }
  63. int
  64. jack_client_suspend(jack_client_t * client)
  65. {
  66. int err = 0;
  67. mach_msg_header_t * head = &client->message.header;
  68. head->msgh_bits = MACH_MSGH_BITS(MACH_MSG_TYPE_COPY_SEND,MACH_MSG_TYPE_MAKE_SEND_ONCE);
  69. head->msgh_remote_port = client->serverport;
  70. head->msgh_local_port = client->replyport;
  71. head->msgh_size = sizeof(mach_msg_header_t);
  72. err = mach_msg(head, MACH_SEND_MSG|MACH_RCV_MSG|MACH_SEND_TIMEOUT,
  73. sizeof(mach_msg_header_t), sizeof(client->message), client->replyport, WAIT, MACH_PORT_NULL);
  74. if (err) {
  75. jack_error("jack_client_suspend: RPC error: %s\n", mach_error_string(err));
  76. return -1;
  77. }
  78. return 0;
  79. }
  80. void
  81. allocate_mach_serverport(jack_engine_t * engine, jack_client_internal_t *client)
  82. {
  83. char buf[256];
  84. snprintf(buf, 256, "JackMachPort_%d", engine->portnum);
  85. if (mach_port_allocate(engine->servertask, MACH_PORT_RIGHT_RECEIVE, &client->serverport)){
  86. jack_error("allocate_mach_serverport: can't allocate mach port");
  87. }
  88. if (mach_port_insert_right(engine->servertask, client->serverport, client->serverport, MACH_MSG_TYPE_MAKE_SEND)){
  89. jack_error("allocate_mach_serverport: error inserting mach rights");
  90. }
  91. if (bootstrap_register(engine->bp, buf, client->serverport)){
  92. jack_error("allocate_mach_serverport: can't check in mach port");
  93. }
  94. client->portnum = engine->portnum;
  95. engine->portnum++;
  96. }
  97. int
  98. allocate_mach_clientport(jack_client_t * client, int portnum)
  99. {
  100. char buf[256];
  101. snprintf(buf, 256, "JackMachPort_%d", portnum);
  102. if (bootstrap_look_up(client->bp, buf, &client->serverport)){
  103. jack_error ("allocate_mach_clientport: can't find mach server port");
  104. return -1;
  105. }
  106. if (mach_port_allocate(client->clienttask, MACH_PORT_RIGHT_RECEIVE, &client->replyport)){
  107. jack_error("allocate_mach_clientport: can't allocate mach port");
  108. return -1;
  109. }
  110. return 0;
  111. }