Exemplo n.º 1
0
/*
 * Send a FakeDLM message to a peer node.
 */
static bool
send_msg(struct node *node, enum msg_type type, const char *lockspace_name)
{
	struct proto_msg msg = {
		.msg = htons(type),
	};
	int ret;

	if (node->outgoing_fd == -1)
		return false;

	if (verbose) {
		printf("> %u %s", node->nodeid,
		       msg_name(type));
		if (lockspace_name)
			printf(" %s", lockspace_name);
		printf("\n");
		fflush(stdout);
	}
	if (lockspace_name)
		strncpy(msg.lockspace_name, lockspace_name,
			DLM_LOCKSPACE_LEN);
	ret = write(node->outgoing_fd, &msg, sizeof(msg));
	if (ret != sizeof(msg)) {
		if (ret > 0)
			errno = EIO;
		fprintf(stderr, "%u: %m\n", node->nodeid);
		close_connections(node);
		return false;
	}
	return true;
}
Exemplo n.º 2
0
/*
 * The incoming or outgoing socket of a node can be read from.  We try to
 * connect to peer nodes asynchronously, so we can get ECONNREFUSED errors
 * here.
 */
static void
proto_read(int fd, short revents, void *arg)
{
	char buf[sizeof(struct proto_msg) + 1];
	struct proto_msg *msg = (void *)buf;
	struct node *node = arg;
	ssize_t ret;

	buf[sizeof(struct proto_msg)] = 0;
	for(;;) {
		ret = read(fd, buf, sizeof(struct proto_msg));
		if (ret == -1) {
			if (errno == EAGAIN || errno == EWOULDBLOCK)
				return;
			if (errno == ECONNREFUSED)
				ret = 0;
		}
		if (ret == 0) {
			proto_close(fd, node);
			return;
		}
		if (ret != sizeof(struct proto_msg))
			fail(NULL);
		if (verbose) {
			printf("< %u %s", node->nodeid,
			       msg_name(ntohs(msg->msg)));
			if (msg->lockspace_name)
				printf(" %s", msg->lockspace_name);
			printf("\n");
			fflush(stdout);
		}
		switch(ntohs(msg->msg)) {
		case MSG_CLOSE:
			proto_close(fd, node);
			return;

		case MSG_LOCKSPACE_STOPPED:
			proto_lockspace_stopped(node, msg->lockspace_name);
			break;

		case MSG_STOP_LOCKSPACE:
			proto_stop_lockspace(node, msg->lockspace_name);
			break;

		case MSG_JOIN_LOCKSPACE:
			proto_join_lockspace(node, msg->lockspace_name);
			break;

		case MSG_LEAVE_LOCKSPACE:
			proto_leave_lockspace(node, msg->lockspace_name);
			break;

		default:
			failf("Unknown message %u received", ntohs(msg->msg));
		}
	}
}
Exemplo n.º 3
0
/* -------------------------------------
 * gap_sdl_cmd
 * -------------------------------------
 * perform simple audio_player command .
 * Note: some of the commands do not make sense
 *       in this SDL based implementation
 *       and are just dummies for compatibility with the
 *       API (that was designed base on the older wavplay client functions)
 */
int
gap_sdl_cmd(int cmd,int flags,GapSdlErrFunc erf) {
  static char *sdl_no_error_available = "";
  char *sdl_error;
  int rc = 1;
  AudioPlaybackThreadUserData  *usrPtr;


  sdl_error = sdl_no_error_available;
  usrPtr = getUsrPtr();
  if (usrPtr != NULL)
  {
    if(gap_debug)
    {
      printf("gap_sdl_cmd cmd:%d (%s) flags:%d SdlAudioStatus:%d\n"
            , cmd
           , msg_name(cmd)
           , flags
           , (int)SDL_GetAudioStatus()
           );
    }
    switch(cmd)
    {
      case GAP_SDL_CMD_Bye:
        stop_audio();
        close_files();
        rc = 0;  /* OK */
        break;
      case GAP_SDL_CMD_Play:
        rc = start_audio();
        sdl_error = SDL_GetError();  /* SDL_GetError uses sttically allocated message that must NOT be freed */
        break;
      case GAP_SDL_CMD_Pause:
        stop_audio();
        rc = 0;  /* OK */
        break;
      case GAP_SDL_CMD_Stop:
        stop_audio();
        close_files();
        rc = 0;  /* OK */
        break;
      case GAP_SDL_CMD_Restore:
        stop_audio();
        rc = 0;  /* OK */
        break;
      case GAP_SDL_CMD_SemReset:
        rc = 0;  /* OK */
        break;
    }

  }


  if ((rc != 0) && (erf != NULL ))
  {
    call_errfunc(erf, "%s: Sending cmd%d to audio_player failed (rc:%d) err:%s",
                        msg_name(cmd),
                        cmd,
                        sdl_error,
                        rc);
  }
  if(gap_debug)
  {
    printf("gap_sdl_cmd cmd:%d (%s) flags:%d retcode:%d\n", cmd, msg_name(cmd), flags, rc);
  }
  return rc;  /* Zero indicates success */

}  /* end gap_sdl_cmd */