本文整理汇总了C++中send_request函数的典型用法代码示例。如果您正苦于以下问题:C++ send_request函数的具体用法?C++ send_request怎么用?C++ send_request使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了send_request函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: network_status
void network_status(){
dhcp_pair *pair = NULL;
pair = (dhcp_pair *) malloc(sizeof(dhcp_pair));
memset(pair, 0, sizeof(dhcp_pair));
// Read from /tmp/wista.txt or from command to get mac link to server
read_wlan_client(pair);
// Form json to get ip
char *json = form_request_json(pair);
// Send Request
char response[4096];
int resp_len;
memset(response, 0, sizeof(response));
//send_request("192.168.48.1", PORT, "/dhcplease", json, strlen(json), response, resp_len);
send_request("127.0.0.1", PORT, "/dhcplease", json, strlen(json), response, resp_len);
//printf("response[%d]=[%s]\n", resp_len, response);
char *p = strstr(response, "\r\n\r\n");
if (p) {
parse_response_json(p+strlen("\r\n\r\n"), pair);
}
result_array ret[64];
memset(&ret, 0, sizeof(ret));
int i=0;
for(i=0; i<pair->length; i++) {
//printf("mac[%d]=%s\n", i, pair->value[i].mac);
//printf(" ip[%d]=%s\n", i, pair->value[i].ip);
ret[i] = network_delay(pair->value[i].ip);
int j=0;
for (j=0; j< PKT_LEN; j++)
printf("ip[%s]-max[%f]-min[%f]-avg[%f]\n", pair->value[i].ip,
ret[i].icmp[j].max, ret[i].icmp[j].min, ret[i].icmp[j].avg);
}
//TODO: No json defined
//Form json post to magicwifi
//Send request to magicwifi
}
示例2: interpret
/*
* Interpret - Read and pass GET request for client
*/
int interpret(int client) {
struct HTTP_Request req;
char buf[BUFSIZE];
char current[BUFSIZE];
char resp[BUFSIZE];
int read_len = 0;
int len = 0;
int rv;
fd_set set;
FD_ZERO(&set);
FD_SET(client, &set);
struct timeval timeout;
timeout.tv_sec = 10;
while ((rv = select(client + 1, &set, NULL, NULL, &timeout)) > 0) {
/* Read input from user */
read_len = recv(client, &buf[len], (BUFSIZE-len), 0);
/* Finish request if buf is empty */
if (strlen(buf) == 0) {
printf("BUF IS EMPTY\n");
break;
}
/* Overwrite trailing new line */
buf[read_len-1] = '\0';
strcpy(req.site, "192.168.2.1");
printf("'%s'\n", buf);
strcpy(req.full_req, buf);
req.port = 22;
if (send_request(client, req) < 0) {
errexit("echo write: %s\n", strerror(errno));
}
}
printf("Exiting\n");
return 0;
}
示例3: request_fetchfields
/*
* Fetch the specified header fields, ie. BODY[HEADER.FIELDS (<fields>)], of
* the messages.
*/
int
request_fetchfields(session *ssn, const char *mesg, const char *headerfields,
char **fields, size_t *len)
{
int t, r;
{
int n = strlen("BODY.PEEK[HEADER.FIELDS ()]") +
strlen(headerfields) + 1;
char f[n];
snprintf(f, n, "%s%s%s", "BODY.PEEK[HEADER.FIELDS (",
headerfields, ")]");
TRY(t = send_request(ssn, "UID FETCH %s %s", mesg, f));
}
TRY(r = response_fetchbody(ssn, t, fields, len));
return r;
}
示例4: music_button_toggled
static void music_button_toggled (GtkWidget *widget, gpointer data)
{
MMConversation *mmconv = mmconv_from_conv(((MMConversation *) data)->conv);
if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (widget)))
{
if (((MMConversation *) data)->requested)
{
start_session(mmconv);
send_request_confirmed(mmconv);
}
else
{
((MMConversation *) data)->originator = TRUE;
send_request((MMConversation *) data);
}
} else {
session_end((MMConversation *)data);
}
}
示例5: process_request
/* connects to a host on a specified port, sends a string, and gets a
response */
int
process_request (const char *server_address, int server_port, int proto,
const char *send_buffer, char *recv_buffer, int recv_size)
{
int result;
int sd;
result = STATE_OK;
result = np_net_connect (server_address, server_port, &sd, proto);
if (result != STATE_OK)
return STATE_CRITICAL;
result = send_request (sd, proto, send_buffer, recv_buffer, recv_size);
close (sd);
return result;
}
示例6: dlbindreq
static int
dlbindreq(int fd, bpf_u_int32 sap, char *ebuf)
{
dl_bind_req_t req;
memset((char *)&req, 0, sizeof(req));
req.dl_primitive = DL_BIND_REQ;
/* XXX - what if neither of these are defined? */
#if defined(DL_HP_RAWDLS)
req.dl_max_conind = 1; /* XXX magic number */
req.dl_service_mode = DL_HP_RAWDLS;
#elif defined(DL_CLDLS)
req.dl_service_mode = DL_CLDLS;
#endif
req.dl_sap = sap;
return (send_request(fd, (char *)&req, sizeof(req), "bind", ebuf));
}
示例7: safe_stoi
void ClientParser::read(std::vector<std::string> commands) {
if( commands.size() != 2 ) {
std::cout << "Error: Bad read params" << std::endl;
return;
}
// Get User
auto user = commands.front();
// Get Index
int index = safe_stoi( commands.at(1) );
if( index < 1 ) {
std::cout << "Error: Bad read params" << std::endl;
return;
}
// Send Request
auto client = Client::get_instance();
bool status = client->send_request( Request::get( user, index ) );
if( !status ) {
std::cout << "Error: Request could not send to the server!";
}
// Read Request
auto response = client->read_until('\n');
if( is_error(response) ) {
std::cout << response;
return;
}
std::cout << utils::split( response ).at(1) << std::endl;
int byte_count = std::stoi( utils::split( response ).back() );
std::cout << client->read_for( byte_count ) << std::endl;
}
示例8: gs_snapd_list
JsonArray *
gs_snapd_list (const gchar *macaroon, gchar **discharges,
GCancellable *cancellable, GError **error)
{
guint status_code;
g_autofree gchar *reason_phrase = NULL;
g_autofree gchar *response_type = NULL;
g_autofree gchar *response = NULL;
g_autoptr(JsonParser) parser = NULL;
JsonObject *root;
JsonArray *result;
if (!send_request ("GET", "/v2/snaps", NULL,
macaroon, discharges,
&status_code, &reason_phrase,
&response_type, &response, NULL,
cancellable, error))
return NULL;
if (status_code != SOUP_STATUS_OK) {
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"snapd returned status code %u: %s",
status_code, reason_phrase);
return NULL;
}
parser = parse_result (response, response_type, error);
if (parser == NULL)
return NULL;
root = json_node_get_object (json_parser_get_root (parser));
result = json_object_get_array_member (root, "result");
if (result == NULL) {
g_set_error (error,
GS_PLUGIN_ERROR,
GS_PLUGIN_ERROR_FAILED,
"snapd returned no result");
return NULL;
}
return json_array_ref (result);
}
示例9: send_hostsstartendupdate
void send_hostsstartendupdate(connection_t *c, int start) {
char rawhost[MAX_STRING_SIZE];
char rawdgst[MAX_STRING_SIZE], b64dgst[MAX_STRING_SIZE];
size_t slen, dlen, rlen;
bool choice = false;
/* test if we're are authorized to broadcast the data */
if(!get_config_bool(lookup_config(config_tree, "HostsFilesMaster"), &choice)) return;
if(!choice) return;
/* bootstrapped node? If we're already sent him updates, do not do that again */
if(c->node && c->node->sentupdates) return;
/* Start update session */
dlen = RSA_size(myself->connection->rsa_key);
if (dlen > sizeof(rawdgst)/2) {
logger(LOG_ERR, "Could not %s hosts update session due to digest overflow",
start ? "start" : "end");
return;
}
snprintf(rawhost, sizeof(rawhost), "%s %s %s 0 %zd",
myself->name, myself->name, start ? "START" : "END", dlen);
rlen = strlen(rawhost);
if (!EVP_sign(myself->connection->rsa_key, rawhost, rlen, rawdgst, &dlen)) {
logger(LOG_ERR,
"Could not %s hosts update session due to signing error (probably OOM)",
start ? "start" : "end");
return;
}
if (base64_enclen(dlen) >= MAX_STRING_SIZE) {
logger(LOG_ERR,
"Could not %s hosts update session, base64 digest overflow",
start ? "start" : "end");
return;
}
base64_encode(rawdgst, dlen, b64dgst, sizeof(b64dgst)-1);
send_request(c, "%d %s %s", HOSTUPDATE, rawhost, b64dgst);
}
示例10: check_interfaces
void
check_interfaces(void)
{
struct interface *ifp;
int rc, ifindex_changed = 0;
unsigned int ifindex;
FOR_ALL_INTERFACES(ifp) {
ifindex = if_nametoindex(ifp->name);
if(ifindex != ifp->ifindex) {
debugf("Noticed ifindex change for %s.\n", ifp->name);
ifp->ifindex = 0;
interface_up(ifp, 0);
ifp->ifindex = ifindex;
ifindex_changed = 1;
}
if(ifp->ifindex > 0)
rc = kernel_interface_operational(ifp->name, ifp->ifindex);
else
rc = 0;
if((rc > 0) != if_up(ifp)) {
debugf("Noticed status change for %s.\n", ifp->name);
interface_up(ifp, rc > 0);
}
if(if_up(ifp)) {
/* Bother, said Pooh. We should probably check for a change
in IPv4 addresses at this point. */
check_link_local_addresses(ifp);
check_interface_channel(ifp);
rc = check_interface_ipv4(ifp);
if(rc > 0) {
send_request(ifp, NULL, 0, NULL, 0);
send_update(ifp, 0, NULL, 0, NULL, 0);
}
}
}
if(ifindex_changed)
renumber_filters();
}
示例11: asio_event_unsubscribe
void asio_event_unsubscribe(asio_event_t* ev)
{
if((ev == NULL) ||
(ev->flags == ASIO_DISPOSABLE) ||
(ev->flags == ASIO_DESTROYED))
return;
asio_backend_t* b = asio_get_backend();
if(ev->noisy)
{
asio_noisy_remove();
ev->noisy = false;
}
epoll_ctl(b->epfd, EPOLL_CTL_DEL, ev->fd, NULL);
if(ev->flags & ASIO_TIMER)
{
if(ev->fd != -1)
{
close(ev->fd);
ev->fd = -1;
}
}
if(ev->flags & ASIO_SIGNAL)
{
int sig = (int)ev->nsec;
asio_event_t* prev = ev;
if((sig < MAX_SIGNAL) && _atomic_cas(&b->sighandlers[sig], &prev, NULL))
{
signal(sig, SIG_DFL);
close(ev->fd);
ev->fd = -1;
}
}
ev->flags = ASIO_DISPOSABLE;
send_request(ev, ASIO_DISPOSABLE);
}
示例12: transport_call
/**
* This method is called from the client to start an RPC call.
* @param transport Transport implementation
* @param client Client
* @param method_desc Method descriptor
* @return Returns LWPB_ERR_OK if successful.
*/
static lwpb_err_t transport_call(lwpb_transport_t transport,
struct lwpb_client *client,
const struct lwpb_method_desc *method_desc)
{
struct lwpb_transport_socket_client *socket_client =
(struct lwpb_transport_socket_client *) transport;
lwpb_err_t ret = LWPB_ERR_OK;
void *req_buf = NULL;
size_t req_len;
// Only continue if connected to server
if (socket_client->socket == -1) {
client->done_handler(client, method_desc,
LWPB_RPC_NOT_CONNECTED, client->arg);
goto out;
}
// Allocate a buffer for the request message
ret = lwpb_transport_alloc_buf(transport, &req_buf, &req_len);
if (ret != LWPB_ERR_OK)
goto out;
// Encode the request message
ret = client->request_handler(client, method_desc, method_desc->req_desc,
req_buf, &req_len, client->arg);
if (ret != LWPB_ERR_OK)
goto out;
socket_client->last_method = method_desc;
// Send the request to the server
// TODO check result
send_request(socket_client->socket, method_desc, req_buf, req_len);
out:
// Free allocated requiest message buffer
if (req_buf)
lwpb_transport_free_buf(transport, req_buf);
return ret;
}
示例13: authenticate_with_cookie
static int
authenticate_with_cookie(IPC_Channel *chan, cl_uuid_t *cookie)
{
struct ha_msg * request;
struct ha_msg * reply;
assert(chan != NULL);
assert(cookie != NULL);
if (!(request = create_basic_reqmsg_fields(ST_SIGNON))) {
return ST_FAIL;
}
if (ha_msg_adduuid(request, F_STONITHD_COOKIE, cookie) != HA_OK) {
stdlib_log(LOG_ERR, "cannot add field to ha_msg.");
ZAPMSG(request);
return ST_FAIL;
}
/* Send request/read response */
if (send_request(chan, request, DEFAULT_TIMEOUT) != ST_OK) {
ZAPMSG(request);
return ST_FAIL;
}
ZAPMSG(request);
if (!(reply = recv_response(chan, DEFAULT_TIMEOUT))) {
return ST_FAIL;
}
/* Are we signed on this time? */
if ( TRUE == is_expected_msg(reply, F_STONITHD_TYPE, ST_APIRPL,
F_STONITHD_APIRPL, ST_RSIGNON, TRUE) ) {
if ( !STRNCMP_CONST(
cl_get_string(reply,F_STONITHD_APIRET), ST_APIOK) ) {
ZAPMSG(reply);
return ST_OK;
}
}
ZAPMSG(reply);
return ST_FAIL;
}
示例14: main
int main()
{
fd_set rfds;
struct timeval tv;
int sock;
uint32_t xid;
sock = init_socket();
xid = send_request(sock);
FD_ZERO(&rfds);
FD_SET(sock, &rfds);
tv.tv_sec = 5;
tv.tv_usec = 0;
if (select(sock + 1, &rfds, NULL, NULL, &tv) == 1 && FD_ISSET(sock, &rfds))
get_reply(sock, xid);
close(sock);
exit(1);
}
示例15: socket_server_listen
int
socket_server_listen(struct socket_server *ss, const char * addr, int port, int backlog) {
struct request_package request;
int len = (addr!=NULL) ? strlen(addr) : 0;
if (len + sizeof(request.u.listen) > sizeof(request.u)) {
fprintf(stderr, "socket-server : Invalid listen addr %s.\n",addr);
return 0;
}
int session = allocsession(ss);
request.u.listen.session = session;
request.u.listen.port = port;
request.u.listen.backlog = backlog;
if (len == 0) {
request.u.listen.host[0] = '\0';
} else {
strcpy(request.u.listen.host, addr);
}
send_request(ss, &request, 'L', sizeof(request.u.listen) + len);
return session;
}