コード例 #1
0
ファイル: network.cpp プロジェクト: richardy2012/rDSN
    bool rpc_session::on_disconnected(bool is_write)
    {
        bool ret;
        if (set_disconnected())
        {
            rpc_session_ptr sp = this;
            if (is_client())
            {
                _net.on_client_session_disconnected(sp);
            }
            else
            {
                _net.on_server_session_disconnected(sp);
            }

            ret = true;
        }
        else
        {
            ret = false;
        }

        if (is_write)
        {
            clear_send_queue(false);
        }

        return ret;
    }
コード例 #2
0
ファイル: network.cpp プロジェクト: ykwd/rDSN
    void rpc_session::start_read_next(int read_next)
    {
        // server only
        if (!is_client())
        {
            int delay_ms = 0;
            {
                utils::auto_lock<utils::ex_lock_nr> l(_lock);
                delay_ms = _delay_server_receive_ms;
                _delay_server_receive_ms = 0;
            }

            // delayed read
            if (delay_ms > 0)
            {
                auto delay_task = dsn_task_create(
                    LPC_DELAY_RPC_REQUEST_RATE,
                    __delayed_rpc_session_read_next__,
                    this
                    );
                this->add_ref(); // released in __delayed_rpc_session_read_next__
                dsn_task_call(delay_task, delay_ms);
            }
            else
            {
                do_read(read_next);
            }
        }
        else
        {
            do_read(read_next);
        }
    }
コード例 #3
0
ファイル: socket_hal.cpp プロジェクト: spark/firmware
sock_result_t socket_send_ex(sock_handle_t sd, const void* buffer, socklen_t len, uint32_t flags, system_tick_t timeout, void* reserved)
{
    sock_result_t result = SOCKET_INVALID;
    socket_t* socket = from_handle(sd);

    uint16_t bytes_sent = 0;

    if (is_open(socket)) {
        std::lock_guard<socket_t> lk(*socket);
        wiced_result_t wiced_result = WICED_TCPIP_INVALID_SOCKET;
        if (is_tcp(socket)) {
            wiced_tcp_send_flags_t wiced_flags = timeout == 0 ? WICED_TCP_SEND_FLAG_NONBLOCK : WICED_TCP_SEND_FLAG_NONE;
            bytes_sent = (uint16_t)len;
            wiced_result = wiced_tcp_send_buffer_ex(tcp(socket), buffer, &bytes_sent, wiced_flags, timeout);
        }
        else if (is_client(socket)) {
            tcp_server_client_t* server_client = client(socket);
            size_t written = 0;
            wiced_result = server_client->write(buffer, len, &written, flags, timeout);
            bytes_sent = (uint16_t)written;
        }
        if (!wiced_result)
            DEBUG("Write %d bytes to socket %d result=%d", (int)len, (int)sd, wiced_result);
        result = wiced_result ? as_sock_result(wiced_result) : bytes_sent;
    }
    return result;
}
コード例 #4
0
/**
 * Returns true if a window can be automatically focused, or false otherwise.
 */
bool ClientModel::is_autofocusable(Window client)
{
    if (!is_client(client))
        return false;

    return m_autofocus[client];
}
コード例 #5
0
/**
 * Either allows, or prevents, a client from being autofocused.
 */
void ClientModel::set_autofocus(Window client, bool can_autofocus)
{
    if (!is_client(client))
        return;

    m_autofocus[client] = can_autofocus;
}
コード例 #6
0
/**
 * Changes the current desktop to the desktop before the current.
 */
void ClientModel::prev_desktop()
{
    // We have to add the maximum desktops back in, since C++ doesn't
    // guarantee what will happen with a negative modulus
    unsigned long long desktop_index =
        (m_current_desktop->desktop - 1 + m_max_desktops)
        % m_max_desktops;

    // We can't change while a window is being moved or resized
    if (m_desktops.count_members_of(MOVING_DESKTOP) > 0 ||
            m_desktops.count_members_of(RESIZING_DESKTOP) > 0)
        return;

    UserDesktop* old_desktop = m_current_desktop;
    m_current_desktop = USER_DESKTOPS[desktop_index];

    Window old_focus = m_focused;
    if (m_focused != None)
    {
        if (is_child(m_focused) && !is_visible(get_parent_of(m_focused)))
            unfocus(false);

        if (is_client(m_focused) && !is_visible(m_focused))
            unfocus(false);
    }

    m_changes.push(new ChangeCurrentDesktop(old_desktop, m_current_desktop));

    // If we can still focus the window we were focused on before, then do so
    // Otherwise, figure out the next logical window in the focus cycle
    if (m_focused != None && m_focused == old_focus)
        m_current_desktop->focus_cycle.set(m_focused);
    else
        sync_focus_to_cycle();
}
コード例 #7
0
bool is_msm_hw3d_file(struct file *file)
{
	struct hw3d_info *info = hw3d_info;
	if (MAJOR(file->f_dentry->d_inode->i_rdev) == MAJOR(info->devno) &&
	    (is_master(info, file) || is_client(info, file)))
		return 1;
	return 0;
}
コード例 #8
0
ファイル: socket_hal.cpp プロジェクト: spark/firmware
wiced_tcp_socket_t* as_wiced_tcp_socket(socket_t* socket)
{
    if (is_tcp(socket)) {
        return tcp(socket);
    }
    else if (is_client(socket)) {
        return socket->s.tcp_client->get_socket();
    }
    return NULL;
}
コード例 #9
0
ファイル: network.cpp プロジェクト: richardy2012/rDSN
    bool rpc_session::on_recv_message(message_ex* msg, int delay_ms)
    {
        if (msg->header->from_address.is_invalid())
            msg->header->from_address = _remote_addr;
        msg->to_address = _net.address();
        msg->io_session = this;

        if (msg->header->context.u.is_request)
        {
            // ATTENTION: need to check if self connection occurred.
            //
            // When we try to connect some socket in the same host, if we don't bind the client to a specific port,
            // operating system will provide ephemeral port for us. If it's happened to be the one we want to connect to,
            // it causes self connection.
            //
            // The case is:
            // - this session is a client session
            // - the remote address is in the same host
            // - the remote address is not listened, which means the remote port is not occupied
            // - operating system chooses the remote port as client's ephemeral port
            if (is_client() && msg->header->from_address == _net.engine()->primary_address())
            {
                derror("self connection detected, address = %s", msg->header->from_address.to_string());
                dassert(msg->get_count() == 0,
                    "message should not be referenced by anybody so far");
                delete msg;
                return false;
            }

            dbg_dassert(!is_client(), "only rpc server session can recv rpc requests");
            _net.on_recv_request(msg, delay_ms);
        }

        // both rpc server session and rpc client session can receive rpc reply
        // specially, rpc client session can receive general rpc reply,  
        // and rpc server session can receive forwarded rpc reply  
        else
        {
            _matcher->on_recv_reply(&_net, msg->header->id, msg, delay_ms);
        }

        return true;
    }
コード例 #10
0
ファイル: mpxio_rcm.c プロジェクト: AlainODea/illumos-gate
/*
 * A libdevinfo di_walk_node() callback.  It's passed an integer pointer as an
 * argument, and it increments the integer each time it encounters an MPxIO
 * client.  By initializing the integer to zero and doing a libdevinfo walk with
 * this function, the total count of MPxIO clients in the system can be found.
 */
static int
get_nclients(di_node_t dinode, void *arg)
{
	int *nclients = arg;

	if (is_client(dinode))
		(*nclients)++;

	return (DI_WALK_CONTINUE);
}
コード例 #11
0
/**
 * Gets the children of a client.
 */
void ClientModel::get_children_of(Window client,
                                  std::vector<Window> &return_children)
{
    if (!is_client(client))
        return;

    for (std::set<Window>::iterator child = m_children[client]->begin();
         child != m_children[client]->end();
         child++)
    {
        return_children.push_back(*child);
    }
}
コード例 #12
0
ファイル: network.cpp プロジェクト: am11/rDSN
    void rpc_session::set_connected()
    {
        dassert(is_client(), "must be client session");

        {
            utils::auto_lock<utils::ex_lock_nr> l(_lock);
            dassert(_connect_state == SS_CONNECTING, "session must be connecting");
            _connect_state = SS_CONNECTED;
        }

        rpc_session_ptr sp = this;
        _net.on_client_session_connected(sp);
    }
コード例 #13
0
/**
 * Removes a client.
 *
 * Note that this method will put out a ChangeFocus event, but that event will
 * have a nonexistent 'prev_focus' field (pointing to the client that is
 * destroyed). Other than that event, however, no other notification will be
 * delivered that this window was removed.
 */
void ClientModel::remove_client(Window client)
{
    if (!is_client(client))
        return;

    // Unregister the client from any categories it may be a member of, but
    // keep a copy of each of the categories so we can pass it on to notify
    // that the window was destroyed (don't copy the size/location though,
    // since they will most likely be invalid, and of no use anyway)
    Desktop *desktop = find_desktop(client);
    Layer layer = find_layer(client);

    if (desktop->is_user_desktop())
    {
        UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(desktop);
        user_desktop->focus_cycle.remove(client, true);
        sync_focus_to_cycle();
    }
    else if (desktop->is_all_desktop())
    {
        dynamic_cast<AllDesktops*>(ALL_DESKTOPS)->focus_cycle.remove(client, true);
        sync_focus_to_cycle();
    }

    // Make sure to remove the child before removing any other parent state - the
    // child removal procedure depends upon knowing the parent's desktop
    std::set<Window> children(*m_children[client]);
    for (std::set<Window>::iterator child = children.begin();
         child != children.end();
         child++)
    {
        remove_child(*child, false);
    }

    m_desktops.remove_member(client);
    m_layers.remove_member(client);
    m_location.erase(client);
    m_size.erase(client);
    m_cps_mode.erase(client);
    m_screen.erase(client);
    m_autofocus.erase(client);
    m_pack_corners.erase(client);
    m_pack_priority.erase(client);

    delete m_children[client];
    m_children.erase(client);

    m_changes.push(new DestroyChange(client, desktop, layer));
}
コード例 #14
0
ファイル: network.cpp プロジェクト: am11/rDSN
    bool rpc_session::try_connecting()
    {
        dassert(is_client(), "must be client session");

        utils::auto_lock<utils::ex_lock_nr> l(_lock);
        if (_connect_state == SS_DISCONNECTED)
        {
            _connect_state = SS_CONNECTING;
            return true;
        }
        else
        {
            return false;
        }
    }
コード例 #15
0
/**
 * Adds a new child window to the given client.
 */
void ClientModel::add_child(Window client, Window child)
{
    if (!is_client(client))
        return;

    if (is_child(child))
        return;

    m_children[client]->insert(child);
    m_parents[child] = client;

    m_changes.push(new ChildAddChange(client, child));

    if (is_autofocusable(client))
    {
        m_current_desktop->focus_cycle.add_after(child, client);
        focus(child);
    }
}
コード例 #16
0
ファイル: network.cpp プロジェクト: ykwd/rDSN
    void rpc_session::on_recv_message(message_ex* msg, int delay_ms)
    {
        msg->to_address = _net.address();
        msg->io_session = this;

        if (msg->header->context.u.is_request)
        {
            dbg_dassert(!is_client(), 
                "only rpc server session can recv rpc requests");
            _net.on_recv_request(msg, delay_ms);
        }

        // both rpc server session and rpc client session can receive rpc reply
        // specially, rpc client session can receive general rpc reply,  
        // and rpc server session can receive forwarded rpc reply  
        else
        {
            _matcher->on_recv_reply(&_net, msg->header->id, msg, delay_ms);
        }
    }
コード例 #17
0
ファイル: socket_hal.cpp プロジェクト: spark/firmware
/**
 * Receives data from a socket.
 * @param sd
 * @param buffer
 * @param len
 * @param _timeout
 * @return The number of bytes read. -1 if the end of the stream is reached.
 */
sock_result_t socket_receive(sock_handle_t sd, void* buffer, socklen_t len, system_tick_t _timeout)
{
    sock_result_t bytes_read = -1;
    socket_t* socket = from_handle(sd);
    if (is_open(socket)) {
        std::lock_guard<socket_t> lk(*socket);
        if (is_tcp(socket)) {
            tcp_socket_t* tcp_socket = tcp(socket);
            tcp_packet_t& packet = tcp_socket->packet;
            bytes_read = read_packet_and_dispose(packet, buffer, len, tcp_socket, _timeout);
        }
        else if (is_client(socket)) {
            tcp_server_client_t* server_client = client(socket);
            bytes_read = read_packet_and_dispose(server_client->packet, buffer, len, server_client->get_socket(), _timeout);
        }
    }
    if (bytes_read<0)
    		DEBUG("socket_receive on %d returned %d", sd, bytes_read);
    return bytes_read;
}
コード例 #18
0
/**
 * Handles an existing client that was unmapped, and is now being re-mapped.
 */
void ClientModel::remap_client(Window client)
{
    if (!is_client(client))
        return;

    std::vector<Window> children;
    get_children_of(client, children);

    Desktop *desktop = find_desktop(client);
    if (desktop->is_user_desktop())
    {
        UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(desktop);
        user_desktop->focus_cycle.add(client);
        for (std::vector<Window>::iterator child = children.begin();
             child != children.end();
             child++)
        {
            user_desktop->focus_cycle.add(*child);
        }

        focus(client);
    }
    else if (desktop->is_all_desktop())
    {
        AllDesktops *all_desktop = dynamic_cast<AllDesktops*>(ALL_DESKTOPS);
        all_desktop->focus_cycle.add(client);
        for (std::vector<Window>::iterator child = children.begin();
             child != children.end();
             child++)
        {
            all_desktop->focus_cycle.add(*child);
        }

        focus(client);
    }

    // The event processor also needs to know that it should update the current 
    // layering, since the window could have been raised since it was remapped
    Layer current_layer = m_layers.get_category_of(client);
    m_changes.push(new ChangeLayer(client, current_layer));
}
コード例 #19
0
/**
 * Changes the focus to another window. Note that this fails if the client
 * is not currently visible.
 *
 * This is used for automated focusing, and is subject to the rules of
 * autofocusing - in particular, if the user enables nofocus for this type of
 * window, then this will do nothing.
 */
void ClientModel::focus(Window client)
{
    Window parent = client;
    if (is_child(client))
        parent = get_parent_of(client);

    if (!is_client(parent))
        return;

    if (!is_visible(parent))
        return;

    if (!m_autofocus[parent])
        return;

    Window old_focus = m_focused;
    m_focused = client;

    m_current_desktop->focus_cycle.set(client);
    m_changes.push(new ChangeFocus(old_focus, client));
}
コード例 #20
0
ファイル: rds.c プロジェクト: aclisp/myqperf
/*
 * Initialize and return open socket.
 */
static int
init(void)
{
    int sockfd;
    uint32_t lport;
    uint32_t rport;
    char lhost[NI_MAXHOST];
    char rhost[NI_MAXHOST];

    if (is_client())
        client_get_hosts(lhost, rhost);
    else
        server_get_hosts(lhost, rhost);
    sockfd = rds_socket(lhost, Req.port);
    lport = get_socket_port(sockfd);
    encode_uint32(&lport, lport);
    send_mesg(&lport, sizeof(lport), "RDS port");
    recv_mesg(&rport, sizeof(rport), "RDS port");
    rport = decode_uint32(&rport);
    rds_makeaddr(&RAddr, &RLen, rhost, rport);
    return sockfd;
}
コード例 #21
0
ファイル: network.cpp プロジェクト: ykwd/rDSN
    bool rpc_session::on_disconnected(bool is_write)
    {
        if (is_client())
        {
            set_disconnected();
            rpc_session_ptr sp = this;
            _net.on_client_session_disconnected(sp);
        }
        
        else
        {
            rpc_session_ptr sp = this;
            _net.on_server_session_disconnected(sp);
        }

        if (is_write)
        {
            clear_send_queue(false);
        }

        return true;
    }
コード例 #22
0
ファイル: qperf-rdma.c プロジェクト: ielhelw/MCMC_FOR_AMMSB
/*
 * Open a RDMA device.
 */
int
rd_open(DEVICE *dev, int trans, int max_send_wr, int max_recv_wr)
{
#if 0
    /* Send request to client */
    if (is_client())
        client_send_request();
#endif

    /* Clear structure */
    memset(dev, 0, sizeof(*dev));

    /* Set transport type and maximum work request parameters */
#if 0
    dev->trans = trans;
#endif
    dev->max_send_wr = max_send_wr;
    dev->max_recv_wr = max_recv_wr;

    /* Open device */
#if 0
    if (Req.use_cm)
        cm_open(dev);
    else
#endif
        int r = ib_open(dev);
    if (r != 0) {
        return r;
    }

    /* Request CQ notification if not polling */
    if (!Req.poll_mode) {
        if (ibv_req_notify_cq(dev->cq, 0) != 0)
            return error(SYS, "failed to request CQ notification");
    }

    return r;
}
コード例 #23
0
/**
 * This is just a way of directly sending an event to the ClientModel - we
 * don't do anything with it.
 */
void ClientModel::unmap_client(Window client)
{
    if (!is_client(client))
        return;

    std::vector<Window> children;
    get_children_of(client, children);

    Desktop *desktop = find_desktop(client);
    if (desktop->is_user_desktop())
    {
        UserDesktop *user_desktop = dynamic_cast<UserDesktop*>(desktop);
        for (std::vector<Window>::iterator child = children.begin();
             child != children.end();
             child++)
        {
            user_desktop->focus_cycle.remove(*child, false);
        }

        user_desktop->focus_cycle.remove(client, false);
        sync_focus_to_cycle();
    }
    else if (desktop->is_all_desktop())
    {
        AllDesktops *all_desktop = dynamic_cast<AllDesktops*>(ALL_DESKTOPS);
        for (std::vector<Window>::iterator child = children.begin();
             child != children.end();
             child++)
        {
            all_desktop->focus_cycle.remove(*child, false);
        }

        all_desktop->focus_cycle.remove(client, false);
        sync_focus_to_cycle();
    }

    m_changes.push(new UnmapChange(client));
}
コード例 #24
0
static int
dissect_gopher(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
    proto_item *ti;
    proto_tree *gopher_tree, *dir_tree = NULL;
    gboolean client = is_client(pinfo);
    gint line_len;
    const gchar *request = "[Invalid request]";
    gboolean is_dir = FALSE;
    gint offset = 0, next_offset;
    gint sel_start, host_start, port_start;
    gchar *name;

    /* Fill in our protocol and info columns */
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "Gopher");

    if (client) {
        line_len = tvb_find_line_end(tvb, 0, -1, NULL, FALSE);
        if (line_len == 0) {
            request = "[Directory list]";
        } else if (line_len > 0) {
            request = tvb_get_ephemeral_string(tvb, 0, line_len);
        }
        col_add_fstr(pinfo->cinfo, COL_INFO, "Request: %s", request);
    } else {
        col_add_fstr(pinfo->cinfo, COL_INFO, "Response");
    }

    if (tree) {
        /* Create display subtree for the protocol */
        ti = proto_tree_add_item(tree, proto_gopher, tvb, 0, -1, ENC_NA);
        gopher_tree = proto_item_add_subtree(ti, ett_gopher);

        if (client) {
            proto_item_append_text(ti, " request: %s", request);
            proto_tree_add_string(gopher_tree, hf_gopher_request, tvb,
                                  0, -1, request);
        } else {
            proto_item_append_text(ti, " response: ");

            while (find_dir_tokens(tvb, offset + 1, &sel_start, &host_start, &port_start, &line_len, &next_offset)) {
                if (!is_dir) { /* First time */
                    proto_item_append_text(ti, "[Directory list]");
                    col_append_fstr(pinfo->cinfo, COL_INFO, ": [Directory list]");
                }

                name = tvb_get_string(tvb, offset + 1, sel_start - offset - 2);
                ti = proto_tree_add_string(gopher_tree, hf_gopher_dir_item, tvb,
                                offset, line_len + 1, name);
                g_free(name);
                dir_tree = proto_item_add_subtree(ti, ett_dir_item);
                proto_tree_add_item(dir_tree, hf_gopher_di_type, tvb, offset, 1, ENC_BIG_ENDIAN);
                proto_tree_add_item(dir_tree, hf_gopher_di_name, tvb, offset + 1,
                                    sel_start - offset - 2, ENC_ASCII|ENC_NA);
                proto_tree_add_item(dir_tree, hf_gopher_di_selector, tvb, sel_start,
                                    host_start - sel_start - 1, ENC_ASCII|ENC_NA);
                proto_tree_add_item(dir_tree, hf_gopher_di_host, tvb, host_start,
                                    port_start - host_start - 1, ENC_ASCII|ENC_NA);
                proto_tree_add_item(dir_tree, hf_gopher_di_port, tvb, port_start,
                                    line_len - (port_start - offset - 1), ENC_ASCII|ENC_NA);
                is_dir = TRUE;
                offset = next_offset;
            }

            if (!is_dir) {
                proto_item_append_text(ti, "[Unknown]");
                proto_tree_add_item(gopher_tree, hf_gopher_unknown, tvb, 0, -1, ENC_ASCII|ENC_NA);
            }
        }

    }

    /* Return the amount of data this dissector was able to dissect */
    return tvb_length(tvb);
}
コード例 #25
0
    remain -= *host_start - *sel_start;
    *port_start = tvb_find_guint8(tvb, *host_start, remain, '\t') + 1;
    if (*port_start < *host_start + 1)
        return FALSE;

    return TRUE;
}

/* Dissect the packets */

static int
dissect_gopher(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
    proto_item *ti;
    proto_tree *gopher_tree, *dir_tree = NULL;
    gboolean client = is_client(pinfo);
    gint line_len;
    const gchar *request = "[Invalid request]";
    gboolean is_dir = FALSE;
    gint offset = 0, next_offset;
    gint sel_start, host_start, port_start;
    gchar *name;

    /* Fill in our protocol and info columns */
    col_set_str(pinfo->cinfo, COL_PROTOCOL, "Gopher");

    if (client) {
        line_len = tvb_find_line_end(tvb, 0, -1, NULL, FALSE);
        if (line_len == 0) {
            request = "[Directory list]";
        } else if (line_len > 0) {
コード例 #26
0
ファイル: socket_hal.cpp プロジェクト: spark/firmware
 /**
  * Find the index of the given client socket in our list of client sockets.
  * @param socket The socket to find.
  * @return The index of the socket (>=0) or -1 if not found.
  */
 int index(wiced_tcp_socket_t* socket) {
     return (is_client(socket)) ? socket-this->WICED_SOCKET_ARRAY : -1;
 }
コード例 #27
0
ファイル: socket_hal.cpp プロジェクト: spark/firmware
inline tcp_server_client_t* client(socket_t* socket) { return is_client(socket) ? socket->s.tcp_client : NULL; }