Пример #1
0
const char *BZ2_bzlibVersion(void) {
  static const char *method = "BZ2_bzlibVersion";
  static const char *saved_version = NULL;
  if (saved_version) {
    api_("%s() return '%s' <= (saved)", method, saved_version);
    return saved_version;
  }

  struct DriverConnection *conn = CreateConnection();
  DBusMessage *msg = ConnectionNewRequest(conn, method);

  DBusError err;
  dbus_error_init(&err);
  api_("%s() =>", method);
  DBusMessage *rsp = ConnectionBlockingSendReply(conn, msg, &err);
  assert (rsp != NULL);

  DBusMessageIter rsp_it;
  dbus_message_iter_init(rsp, &rsp_it);
  assert (dbus_message_iter_get_arg_type(&rsp_it) == DBUS_TYPE_STRING);
  const char *retval;
  dbus_message_iter_get_basic(&rsp_it, &retval);
  dbus_message_iter_next(&rsp_it);
  api_("%s() return '%s' <=", method, retval);
  saved_version = strdup(retval);
  dbus_message_unref(rsp);
  DestroyConnection(conn);
  return saved_version;
}
Пример #2
0
int BZ2_bzTestStream(int ifd, int verbosity, int small) {
  static const char *method = "BZ2_bzTestStream";
  struct DriverConnection *conn = CreateConnection();
  DBusMessage *msg = ConnectionNewRequest(conn, method);

  DBusMessageIter msg_it;
  dbus_message_iter_init_append(msg, &msg_it);
  dbus_int32_t vx;
  vx = ifd;
  dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_UNIX_FD, &vx);
  vx = verbosity;
  dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);
  vx = small;
  dbus_message_iter_append_basic(&msg_it, DBUS_TYPE_INT32, &vx);

  DBusError err;
  dbus_error_init(&err);
  api_("%s(%d, %d, %d) =>", method, ifd, verbosity, small);
  DBusMessage *rsp = ConnectionBlockingSendReply(conn, msg, &err);
  assert (rsp != NULL);

  DBusMessageIter rsp_it;
  dbus_message_iter_init(rsp, &rsp_it);
  assert (dbus_message_iter_get_arg_type(&rsp_it) == DBUS_TYPE_INT32);
  dbus_message_iter_get_basic(&rsp_it, &vx);
  dbus_message_iter_next(&rsp_it);
  int retval = vx;
  api_("%s(%d, %d, %d) return %d <=", method, ifd, verbosity, small, retval);
  dbus_message_unref(rsp);
  DestroyConnection(conn);
  return retval;
}
Пример #3
0
//目前只保证connlist里面空闲连接被释放,剩下的分配出去的连接
//还没有去管,基于不是程序退出不会销毁线程池,所以也没关系
void ConnPool::DestroyConnPool(){
	list<MysqlEncap *>::iterator iter;
	MutexGuard lock(mutex);
	for(iter=connList.begin(); iter!=connList.end(); iter++){
		DestroyConnection(*iter);
	}
	curSize = 0;
	connList.clear();
}
Пример #4
0
ULONG
GetServerTime(LPWSTR lpAddress)
{
    PINFO pInfo;
    LPSTR lpAddr;
    DWORD dwSize = wcslen(lpAddress) + 1;
    ULONG ulTime = 0;

    pInfo = (PINFO)HeapAlloc(GetProcessHeap(),
                             0,
                             sizeof(INFO));
    lpAddr = (LPSTR)HeapAlloc(GetProcessHeap(),
                              0,
                              dwSize);

    if (pInfo && lpAddr)
    {
        if (WideCharToMultiByte(CP_ACP,
                                0,
                                lpAddress,
                                -1,
                                lpAddr,
                                dwSize,
                                NULL,
                                NULL))
        {
            if (InitConnection(pInfo, lpAddr))
            {
                if (SendData(pInfo))
                {
                    ulTime = ReceiveData(pInfo);
                }
            }

            DestroyConnection();
        }
    }

    if (pInfo)
        HeapFree(GetProcessHeap(), 0, pInfo);
    if (lpAddr)
        HeapFree(GetProcessHeap(), 0, lpAddr);

    return ulTime;
}
Пример #5
0
static struct DriverConnection *CreateConnection(void) {
  struct DriverConnection *conn = &g_conn;
  /* Create socket for bootstrap communication with child */
  int socket_fds[2] = {-1, -1};
  int rc = socketpair(AF_UNIX, SOCK_STREAM, 0, socket_fds);
  if (rc < 0) {
    error_("failed to open sockets, errno=%d (%s)", errno, strerror(errno));
    return NULL;
  }

  api_("CreateConnection(g_exe_fd=%d, '%s')", g_exe_fd, g_exe_file);

  conn->pid = fork();
  if (conn->pid < 0) {
    error_("failed to fork, errno=%d (%s)", errno, strerror(errno));
    return NULL;
  }

  if (conn->pid == 0) {
    /* Child process: run the driver */
    close(socket_fds[0]);
    RunDriver(g_exe_fd, g_exe_file, socket_fds[1]);
  }

  /* Read bootstrap information back from the child */
  /* First: uint32_t len, char server_add[len] */
  uint32_t len;
  rc = read(socket_fds[0], &len, sizeof(len));
  assert (rc == sizeof(len));
  char *server_address = (char *)malloc(len);
  rc = read(socket_fds[0], server_address, len);
  assert (rc == len);
  /* Second: uint64_t nonce (used to confirm that the D-Bus connection we set up
   * later is indeed to the child process */
  uint64_t nonce;
  rc = read(socket_fds[0], &nonce, sizeof(nonce));
  assert (rc == sizeof(nonce));
  verbose_("started child process %d, read socket name '%s', nonce %ld",
           conn->pid, server_address, nonce);
  close(socket_fds[0]);
  close(socket_fds[1]);
  snprintf(conn->objpath, 20, "/nonce/%ld", nonce);

  /* Initialize D-Bus private connection; use the nonce as the object address */
  DBusError err;
  dbus_error_init(&err);
  conn->dbus = dbus_connection_open_private(server_address, &err);
  if (!conn->dbus) {
    error_("!!! dbus_connection_open_private failed: %s: %s\n", err.name, err.message);
    free(server_address);
    DestroyConnection(conn);
    return NULL;
  }
  log_("got connection %p to private bus '%s' with {pid=%d dbus_conn=%p objpath='%s'})",
       conn, server_address, conn->pid, conn->dbus, conn->objpath);
  free(server_address);

  /* Send a no-op message to work around a D-Bus problem (if the first message sent
     includes a file descriptor, it fails). */
  DBusMessage *req = ConnectionNewRequest(conn, "__noop");
  DBusMessage *rsp = ConnectionBlockingSendReply(conn, req, &err);
  if (rsp == NULL) {
    DestroyConnection(conn);
    return NULL;
  }
  dbus_message_unref(rsp);

  return conn;
}
Пример #6
0
CNetClient::~CNetClient()
{
	DestroyConnection();
	JS_RemoveExtraGCRootsTracer(GetScriptInterface().GetJSRuntime(), CNetClient::Trace, this);
}