static void handle_request(int iscsi_fd, const struct iscsi_daemon_request *request, int timeout) { struct connection *conn; log_set_peer_addr(request->idr_conf.isc_target_addr); if (request->idr_conf.isc_target[0] != '\0') { log_set_peer_name(request->idr_conf.isc_target); setproctitle("%s (%s)", request->idr_conf.isc_target_addr, request->idr_conf.isc_target); } else { setproctitle("%s", request->idr_conf.isc_target_addr); } conn = connection_new(request->idr_session_id, &request->idr_conf, iscsi_fd); set_timeout(timeout); capsicate(conn); login(conn); if (conn->conn_conf.isc_discovery != 0) discovery(conn); else handoff(conn); log_debugx("nothing more to do; exiting"); exit (0); }
int set_incantation(t_stck *s, int fd, int pause, int (*funct)()) { int i; int *players; int flag; int ressource; i = 0; flag = 1; players = get_players_from_case(s, fd); ressource = check_ressource_for_incant(s, fd); while (players[i]) { flag = s->fds[players[i]].level == s->fds[fd].level ? 1 : 0; i++; } if (flag && (i + 1) == gl_inc_tok[s->fds[fd].level - 1].nb_players && ressource) { set_timeout(s, fd, pause, funct); send_one("elevation en cours", fd, s); event_incant(s, fd, players); } else send_one("ko", fd, s); free(players); return (0); }
static inline void reqread_start(h2o_http1_conn_t *conn) { set_timeout(conn, &conn->super.ctx->req_timeout, reqread_on_timeout); h2o_socket_read_start(conn->sock, reqread_on_read); if (conn->sock->input->size != 0) handle_incoming_request(conn); }
void test_init (int *argcp, char ***argvp) { /* If our argv only contained the executable name, assume we were * run by Automake with LOG_COMPILER overridden by * VALGRIND_CHECK_RULES from AX_VALGRIND_CHECK, and automatically switch * on TAP output. This avoids needing glib-tap-test.sh. We still use * glib-tap-test.sh in the common case because it replaces \r\n line * endings with \n, which we need if running the tests under Wine. */ static char tap[] = "--tap"; static char *substitute_argv[] = { NULL, tap, NULL }; g_return_if_fail (argcp != NULL); g_return_if_fail (*argcp > 0); g_return_if_fail (argvp != NULL); g_return_if_fail (argvp[0] != NULL); g_return_if_fail (argvp[0][0] != NULL); if (*argcp == 1) { substitute_argv[0] = (*argvp)[0]; *argcp = 2; *argvp = substitute_argv; } g_test_init (argcp, argvp, NULL); g_test_bug_base ("https://bugs.freedesktop.org/show_bug.cgi?id="); set_timeout (1); }
void ksymp_set_timeout(KSYMediaPlayer *mp, int size) { assert(mp); pthread_mutex_lock(&mp->mutex); set_timeout(mp->ffplayer, size); pthread_mutex_unlock(&mp->mutex); }
void ssl_want_read(struct connection *c) { struct conn_info *b = c->newconn; set_timeout(c); if (c->no_tsl) c->ssl->options |= SSL_OP_NO_TLSv1; switch (SSL_get_error(c->ssl, SSL_connect(c->ssl))) { case SSL_ERROR_NONE: c->newconn = NULL; b->func(c); mem_free(b); break; case SSL_ERROR_WANT_READ: set_handlers(*b->sock, (void(*)(void *))ssl_want_read, NULL, (void(*)(void *))exception, c); break; case SSL_ERROR_WANT_WRITE: set_handlers(*b->sock, NULL, (void(*)(void *))ssl_want_read, (void(*)(void *))exception, c); break; default: c->no_tsl++; setcstate(c, S_SSL_ERROR); retry_connection(c); break; } }
zchar os_read_line (int max, zchar *buf, int timeout, int width, int continued) { char c; int x,y; int i=0; int t=timeout*100; uint32 s,ms,tm; set_timeout(timeout); timer_ms_gettime(&s,&ms); i=strlen(buf); do { c=os_read_key(-1,1); if(c>=32 && c <= 176) c99_printf("%c",c); switch(c) { case 0: case 13: break; case 8: if(i>0) { i--; buf[i]='\0'; getxy(&x,&y); locate(x-1,y); } break; default: buf[i]=c; i++; break; } } while (c!=13&&c!=0); buf[i]='\0'; return c; }
static void send_file(char *filename, struct sockaddr_in *client, char *addr, int master_sd, uint16_t blksize) { char client_name[INET_ADDRSTRLEN]; int file; int sd; char *message; message = xmalloc(4); memset(message, '\0', 4); if ((file = open(filename, O_RDONLY)) == -1) { send_error(client, TFTP_ERR_UNKNOWN_FILE, (char *)"File not found.", master_sd); return; } if (inet_ntop(AF_INET, &client->sin_addr, client_name, sizeof (client_name))) printf("Uploading %s to %s:%hu\n", filename, client_name, ntohs(client->sin_port)); sd = prepare_socket(addr, 0); set_timeout(sd, 1); process_send_packets(client, blksize, file, sd, message); printf("Done.\n\n"); close(sd); free(message); close(file); }
void h_fast_timer_set() { #ifdef PRODUCTION if (!nw_fast_timer.set) set_timeout(&nw_fast_timer, 1); #endif }
/* * thread_depress_priority * * Depress thread's priority to lowest possible for specified period. * Intended for use when thread wants a lock but doesn't know which * other thread is holding it. As with thread_switch, fixed * priority threads get exactly what they asked for. Users access * this by the SWITCH_OPTION_DEPRESS option to thread_switch. A Time * of zero will result in no timeout being scheduled. */ void thread_depress_priority( thread_t thread, mach_msg_timeout_t depress_time) { unsigned int ticks; spl_t s; /* convert from milliseconds to ticks */ ticks = convert_ipc_timeout_to_ticks(depress_time); s = splsched(); thread_lock(thread); /* * If thread is already depressed, override previous depression. */ reset_timeout_check(&thread->depress_timer); /* * Save current priority, then set priority and * sched_pri to their lowest possible values. */ thread->depress_priority = thread->priority; thread->priority = 31; thread->sched_pri = 31; if (ticks != 0) set_timeout(&thread->depress_timer, ticks); thread_unlock(thread); (void) splx(s); }
static int app_control_dial(struct stasis_app_control *control, struct ast_channel *chan, void *data) { struct control_dial_args *args = data; int bridged; ast_channel_lock(chan); bridged = ast_channel_is_bridged(chan); ast_channel_unlock(chan); if (!bridged && add_to_dial_bridge(control, chan)) { return -1; } if (args->timeout && set_timeout(chan, args->timeout)) { return -1; } if (ast_call(chan, args->dialstring, 0)) { return -1; } ast_channel_publish_dial(NULL, chan, args->dialstring, NULL); return 0; }
void __declspec(dllexport) WINAPI _set_timeout(lprec *lp, long sectimeout) { if (lp != NULL) { freebuferror(); set_timeout(lp, sectimeout); } }
void on_udp_close(uv_handle_t* handle) { UdpSocketBaton* baton = reinterpret_cast<UdpSocketBaton*>(handle); set_timeout(1000, [baton] () { // delete baton; }); }
static void next_state(void) { s_current_state++; if (s_current_state == s_state_count) { if (s_repetitions > 0) { s_repetitions--; } // we've reached the end of the sequence, repeat if (s_repetitions == 0) { // no more repetitions, stop bsp_buzzer_stop(); return; } // go back to the first state s_current_state = 0; } const bsp_buzzer_state_t* state = &s_states[s_current_state]; if (state->freq > 0) { enable_output(s_buzzer,state->freq); } else { disable_output(s_buzzer); } set_timeout(state->ms); }
/* Receive and process packets. For now, returning from * stream_rx_usb() means that UAP and clocks have been found, and that * hopping should be started. A more flexible framework would be * nice. */ void rx_live(ubertooth_t* ut, btbb_piconet* pn, int timeout) { int r = btbb_init(max_ac_errors); if (r < 0) return; if (timeout) set_timeout(ut, timeout); if (ut->follow_pn) cmd_set_clock(ut->devh, 0); else { stream_rx_usb(ut, cb_br_rx, pn); /* Allow pending transfers to finish */ sleep(1); } /* Used when follow_pn is preset OR set by stream_rx_usb above * i.e. This cannot be rolled in to the above if...else */ if (ut->follow_pn) { ut->stop_ubertooth = 0; ut->usb_really_full = 0; // cmd_stop(ut->devh); cmd_set_bdaddr(ut->devh, btbb_piconet_get_bdaddr(ut->follow_pn)); cmd_start_hopping(ut->devh, btbb_piconet_get_clk_offset(ut->follow_pn)); stream_rx_usb(ut, cb_br_rx, ut->follow_pn); } }
static BOOL modem_command (const char *cmd, const char *resp, int timeout) { DWORD timer; int len = cmd ? strlen (cmd) : strlen (resp); if (cmd) rc = pkt_send (cmd, len); /**<\todo Bypass PKTDRVR ? */ if (rc < len || !_eth_is_init) return (FALSE); timer = set_timeout (1000 * timeout); while (!chk_timeout(timer)) { char *pkt = (char*) _eth_arrived (NULL NULL); if (!pkt) continue; outsn (pkt, len); /* print the modem echo */ _eth_free (pkt, type); return (strncmp(pkt,resp,strlen(resp)) == 0); /* got modem response */ } return (FALSE); }
static void ftp_login(struct connection *c) { unsigned char *login; unsigned char *u; int logl = 0; set_timeout(c); login = init_str(); add_to_str(&login, &logl, cast_uchar "USER "); if ((u = get_user_name(c->url)) && *u) add_to_str(&login, &logl, u); else add_to_str(&login, &logl, cast_uchar "anonymous"); if (u) mem_free(u); if (ftp_options.fast_ftp) { struct ftp_connection_info *fi; add_to_str(&login, &logl, cast_uchar "\r\nPASS "); if ((u = get_pass(c->url)) && *u) add_to_str(&login, &logl, u); else add_to_str(&login, &logl, ftp_options.anon_pass); if (u) mem_free(u); add_to_str(&login, &logl, cast_uchar "\r\n"); if (!(fi = add_file_cmd_to_str(c))) { mem_free(login); return; } add_to_str(&login, &logl, fi->cmdbuf); } else add_to_str(&login, &logl, cast_uchar "\r\n"); write_to_socket(c, c->sock1, login, strlen(cast_const_char login), ftp_logged); mem_free(login); setcstate(c, S_SENT); }
static void receive_file(char *filename, struct sockaddr_in *client, char *addr, int master_sd, uint16_t blksize) { char client_name[INET_ADDRSTRLEN]; struct sockaddr_in current_client; FILE *file; int sd; if (!(file = fopen(filename, "w"))) { send_error(client, TFTP_ERR_ACCES_VIOLATION, (char *)"Unable to write to file.", master_sd); return; } if (inet_ntop(AF_INET, &client->sin_addr, client_name, sizeof (client_name))) printf("Downloading %s from %s:%hu\n", filename, client_name, ntohs(client->sin_port)); sd = prepare_socket(addr, 0); set_timeout(sd, 1); if (blksize == TFTP_DEFAULT_BLKSZ) send_ack(sd, client, 0); else send_blksize_ack(sd, client, blksize); process_receive_packets(client, blksize, ¤t_client, file, sd); printf("Done.\n\n"); close(sd); fclose(file); }
static int get_ftp_response(struct connection *c, struct read_buffer *rb, int part) { int l; set_timeout(c); again: for (l = 0; l < rb->len; l++) if (rb->data[l] == 10) { unsigned char *e; long k = strtoul(cast_const_char rb->data, (char **)(void *)&e, 10); if (e != rb->data + 3 || k < 100 || k >= 1000) return -1; if (*e == '-') { int i; for (i = 0; i < rb->len - 5; i++) { if (rb->data[i] == 10 && !memcmp(rb->data+i+1, rb->data, 3) && rb->data[i+4] == ' ') { for (i++; i < rb->len; i++) if (rb->data[i] == 10) goto ok; return 0; } } return 0; ok: l = i; } if (!part && k >= 100 && k < 200) { kill_buffer_data(rb, l + 1); goto again; } if (part == 2) return k; kill_buffer_data(rb, l + 1); return k; } return 0; }
static void settle_timeout(struct timer_list *t) { struct floppy_state *fs = from_timer(fs, t, timeout); struct swim3 __iomem *sw = fs->swim3; unsigned long flags; swim3_dbg("* settle timeout, state=%d\n", fs->state); spin_lock_irqsave(&swim3_lock, flags); fs->timeout_pending = 0; if (swim3_readbit(fs, SEEK_COMPLETE)) { out_8(&sw->select, RELAX); fs->state = locating; act(fs); goto unlock; } out_8(&sw->select, RELAX); if (fs->settle_time < 2*HZ) { ++fs->settle_time; set_timeout(fs, 1, settle_timeout); goto unlock; } swim3_err("%s", "Seek settle timeout\n"); swim3_end_request(fs, BLK_STS_IOERR, 0); fs->state = idle; start_request(fs); unlock: spin_unlock_irqrestore(&swim3_lock, flags); }
int serial_open(urg_serial_t *serial, const char *device, long baudrate) { // COM10 以降への対応用 enum { NameLength = 11 }; char adjusted_device[NameLength]; serial_initialize(serial); /* COM ポートを開く */ _snprintf(adjusted_device, NameLength, "\\\\.\\%s", device); serial->hCom = CreateFileA(adjusted_device, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (serial->hCom == INVALID_HANDLE_VALUE) { // !!! store error_message buffer //printf("open failed: %s\n", device); return -1; } /* 通信サイズの更新 */ SetupComm(serial->hCom, 4096 * 8, 4096); /* ボーレートの変更 */ serial_set_baudrate(serial, baudrate); /* シリアル制御構造体の初期化 */ serial->has_last_ch = False; /* タイムアウトの設定 */ serial->current_timeout = 0; set_timeout(serial, serial->current_timeout); return 0; }
static void on_entity_read_complete(h2o_http1_conn_t *conn) { conn->_req_entity_reader = NULL; set_timeout(conn, NULL, NULL); h2o_socket_read_stop(conn->sock); process_request(conn); }
/** * Processes an incoming REG_CONF message. * Expected in response to a REGISTER when encryption is disabled. */ void handle_regconf(struct group_list_t *group, const unsigned char *message, unsigned meslen) { const struct regconf_h *regconf; const uint32_t *addrlist; int addrcnt; regconf = (const struct regconf_h *)message; addrlist = (const uint32_t *)(message + (regconf->hlen * 4)); if ((meslen < (regconf->hlen * 4U)) || ((regconf->hlen * 4U) < sizeof(struct regconf_h))) { glog1(group, "Rejecting REG_CONF from server: invalid message size"); return; } addrcnt = (meslen - (regconf->hlen * 4)) / 4; if (uid_in_list(addrlist, addrcnt)) { glog2(group, "Registration confirmed"); group->phase = PHASE_MIDGROUP; set_timeout(group, 0); } if (group->restart) { read_restart_file(group); } }
int resolve_ip (DWORD ip, char *result) { question_t q; WORD oldhndlcbrk; int i; if (dns_timeout == 0) dns_timeout = sock_delay << 2; resolve_timeout = set_timeout (100 * dns_timeout); oldhndlcbrk = wathndlcbrk; wathndlcbrk = 1; /* enable special interrupt mode */ watcbroke = 0; *result = 0; _resolve_exit = 0; qinit (&q,ip); for (i = 0; i < last_nameserver; ++i) { if (!reverse_lookup(&q,result,def_nameservers[i])); break; } watcbroke = 0; /* always clean up */ wathndlcbrk = oldhndlcbrk; return (*result != 0); }
void finger_get_response(struct connection *c, struct read_buffer *rb) { struct cache_entry *e; int l; set_timeout(c); if (get_cache_entry(c->url, &e)) { setcstate(c, S_OUT_OF_MEM); abort_connection(c); return; } c->cache = e; if (rb->close == 2) { setcstate(c, S_OK); finger_end_request(c); return; } l = rb->len; if (c->from + l < 0) { setcstate(c, S_LARGE_FILE); abort_connection(c); return; } c->received += l; if (add_fragment(c->cache, c->from, rb->data, l) == 1) c->tries = 0; c->from += l; kill_buffer_data(rb, l); read_from_socket(c, c->sock1, rb, finger_get_response); setcstate(c, S_TRANS); }
bool session::set_ttl(time_t ttl, bool delay) { if (ttl == ttl_) return true; // 如果是延迟修改,则仅设置相关成员变量,最后统一 flush else if (delay) { ttl_ = ttl; dirty_ = true; return true; } // 如果该 sid 还没有在后端 cache 上存储过,则仅在对象中本地设置一下 else if (!sid_saved_) { ttl_ = ttl; return true; } // 修改后端 cache 上针对该 sid 的 ttl else if (set_timeout(ttl) == true) { ttl_ = ttl; return true; } else return false; }
/* Receive and process packets. For now, returning from * stream_rx_usb() means that UAP and clocks have been found, and that * hopping should be started. A more flexible framework would be * nice. */ void rx_live(struct libusb_device_handle* devh, btbb_piconet* pn, int timeout) { int r = btbb_init(max_ac_errors); if (r < 0) return; if (timeout) set_timeout(timeout); if (follow_pn) cmd_set_clock(devh, 0); else { stream_rx_usb(devh, XFER_LEN, 0, cb_br_rx, pn); /* Allow pending transfers to finish */ sleep(1); } /* Used when follow_pn is preset OR set by stream_rx_usb above * i.e. This cannot be rolled in to the above if...else */ if (follow_pn) { cmd_stop(devh); cmd_set_bdaddr(devh, btbb_piconet_get_bdaddr(follow_pn)); cmd_start_hopping(devh, btbb_piconet_get_clk_offset(follow_pn)); stream_rx_usb(devh, XFER_LEN, 0, cb_br_rx, follow_pn); } }
/** * Send an ICMP destination/protocol unreachable back to 'ip->source'. * Limit the rate of these to 20 per second. Ref. RFC-1812. */ int icmp_send_unreach (const in_Header *ip, int code) { static DWORD next_time = 0UL; struct _pkt *pkt; union ICMP_PKT *unr; unsigned len; if (!icmp_check(ip,ICMP_UNREACH)) return (0); if (next_time && !chk_timeout(next_time)) return (0); next_time = set_timeout (50); pkt = (struct _pkt*) _eth_formatpacket (MAC_SRC(ip), IP4_TYPE); unr = &pkt->icmp; len = intel16 (ip->length) - in_GetHdrLen (ip); len = min (len, sizeof(*ip)+sizeof(unr->unused.spares)); icmp_print (1, _LANG(icmp_unreach_str[code]), ip->destination); memcpy (&unr->unused.ip, ip, len); unr->unused.type = ICMP_UNREACH; unr->unused.code = (BYTE) code; return icmp_send (pkt, ip->destination, ip->source, sizeof(unr->unused)); }
/* * _dorarp - Checks global variable _rarptimeout * returns 1 on success and sets ip address */ int _dorarp (void) { DWORD rarptimeout = set_timeout (1000 * _rarptimeout); WORD magictimeout = Random (7000, 14000); outs (_LANG("Configuring through RARP...")); while (1) { DWORD sendtimeout; if (!_rarp_request()) break; sendtimeout = set_timeout (magictimeout); magictimeout += Random (1000, 7000); while (!chk_timeout(sendtimeout)) { const struct rarp_Header *rarp; WORD eth_type; BOOL bcast; if (chk_timeout(rarptimeout)) return (0); WATT_YIELD(); rarp = (rarp_Header*) _eth_arrived (ð_type, &bcast); if (!rarp) continue; DEBUG_RX (NULL, rarp); if (eth_type == RARP_TYPE && !bcast && rarp->opcode == RARP_REPLY && rarp->protType == IP4_TYPE && !memcmp(rarp->dstEthAddr,_eth_addr,sizeof(mac_address))) { my_ip_addr = intel (rarp->dstIPAddr); _eth_free (rarp); return (1); } _eth_free (rarp); } } return (0); }
/* * igmp_handler - handles the incoming IGMP packets * * void igmp_handler (in_Header *ip) * Where: * ip is the IP packet in question * * Returns: None * */ void igmp_handler (const in_Header *ip, BOOL broadcast) { BYTE i; DWORD host; BOOL found = 0; WORD len = in_GetHdrLen (ip); IGMP_packet *igmp = (IGMP_packet*) ((BYTE*)ip + len); DEBUG_RX (NULL, ip); if (len < sizeof(*igmp)) { STAT (igmpstats.igps_rcv_tooshort++); return; } if (checksum(igmp,sizeof(*igmp)) != 0xFFFF) { STAT (igmpstats.igps_rcv_badsum++); return; } host = intel (igmp->address); /* Determine whether this is a report or a query */ switch (igmp->type) { case IGMP_QUERY: STAT (igmpstats.igps_rcv_queries++); for (i = 0; i < IPMULTI_SIZE; i++) if (_ipmulti[i].active && _ipmulti[i].ina != ALL_SYSTEMS && _ipmulti[i].replytime == 0) { _ipmulti[i].replytime = set_timeout (Random(500,1000)); found = 1; } if (!found && !broadcast) STAT (igmpstats.igps_rcv_badqueries++); break; case IGMP_REPORT: STAT (igmpstats.igps_rcv_reports++); for (i = 0; i < IPMULTI_SIZE; i++) if (_ipmulti[i].active && _ipmulti[i].ina == host && host != ALL_SYSTEMS) { _ipmulti[i].replytime = 0; found = 1; STAT (igmpstats.igps_rcv_ourreports++); break; } if (!found && !broadcast) STAT (igmpstats.igps_rcv_badreports++); break; } }