static void port_accept(INT32 args) { PIKE_SOCKADDR addr; struct port *this=THIS; int fd, err; ACCEPT_SIZE_T len=0; int one = 1; if(this->box.fd < 0) Pike_error("port->accept(): Port not open.\n"); /* FIXME: Race. */ THIS->box.revents = 0; THREADS_ALLOW(); len=sizeof(addr); do { fd=fd_accept(this->box.fd, (struct sockaddr *)&addr, &len); err = errno; } while (fd < 0 && err == EINTR); THREADS_DISALLOW(); INVALIDATE_CURRENT_TIME(); if(fd < 0) { this->my_errno=errno = err; pop_n_elems(args); push_int(0); return; } /* We don't really care if setsockopt fails, since it's just a hint. */ while ((fd_setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(int)) < 0) && (errno == EINTR)) one = 1; my_set_close_on_exec(fd,1); push_new_fd_object(port_fd_factory_fun_num, fd, FILE_READ | FILE_WRITE, SOCKET_CAPABILITIES); if (this->box.backend) { struct object *o = Pike_sp[-1].u.object; struct my_file *f = (struct my_file *) (o->storage + o->prog->inherits[SUBTYPEOF(Pike_sp[-1])].storage_offset); change_backend_for_box(&f->box, this->box.backend); } stack_pop_n_elems_keep_top(args); }
net_sock_t *sock_accept(net_sock_t *nsock) { network_sock_t *psock = (network_sock_t *)nsock; network_sock_t *sock = (network_sock_t *)malloc(sizeof(network_sock_t)); assert(sock != NULL); sock->fd = fd_accept(psock->fd); if (sock->fd == -1) { free(sock); sock = NULL; } return(sock); }
static gboolean listen_channel_input_cb(GIOChannel *chan, GIOCondition cond, gpointer data) { gint sock; gchar buf[BUFFSIZE]; if (answer_sock != -1) return TRUE; sock = g_io_channel_unix_get_fd(chan); answer_sock = fd_accept(sock); while (fd_gets(answer_sock, buf, sizeof(buf)) != -1) { g_print("Received request: %s", buf); if(g_str_has_prefix(buf,":request_contacts:")) received_contacts_request(answer_sock); else if(g_str_has_prefix(buf, ":modify_contact:")) received_contact_modify_request(answer_sock); else if(g_str_has_prefix(buf, ":delete_contact:")) received_contact_delete_request(answer_sock); else if(g_str_has_prefix(buf, ":add_contact:")) received_contact_add_request(answer_sock); else if(g_str_has_prefix(buf, ":request_events:")) received_events_request(answer_sock); else if(g_str_has_prefix(buf, ":modify_event:")) received_event_modify_request(answer_sock); else if(g_str_has_prefix(buf, ":delete_event:")) received_event_delete_request(answer_sock); else if(g_str_has_prefix(buf, ":add_event:")) received_event_add_request(answer_sock); else if(g_str_has_prefix(buf,":finished:")) { received_finished_notification(answer_sock); break; } } fd_close(answer_sock); answer_sock = -1; g_print("closed answer sock\n"); return TRUE; }
static gboolean io_callback_sv(GIOChannel * source, GIOCondition condition, gpointer data) { gchar buf[LINE_MAX],tmp[8]; gint fd, readsize; typMascot *mascot = data; gint i_ptn,i_frm; gint mode; fd = fd_accept(g_io_channel_unix_get_fd(source)); readsize = read(fd, buf, LINE_MAX-1); buf[readsize] = '\0'; fd_close(fd); if(readsize<4) return; strncpy(tmp,buf,2); mode=atoi(tmp); strncpy(tmp,buf+2,2); i_ptn=atoi(tmp); if(mode==DUET_CLICK){ if (mascot->sockmsg != NULL) g_free(mascot->sockmsg); mascot->sockmsg=g_strdup(buf+2+2); } // クリックアニメ if((mode==DUET_CLICK)&&(mascot->duet_use_click)){ if(mascot->frame_pix[i_ptn][0]!=-1){ for(i_frm=0;i_frm<mascot->frame_num[mascot->anime_ptn];i_frm++){ // ブロックループのキャンセル mascot->frame_loop[mascot->anime_ptn][i_frm].seq=0; } //mascot->anime_ptn=weight_click(mascot); mascot->anime_ptn=i_ptn; mascot->anime_frm=-1; mascot->anime_seq=-1; mascot->anime_seqend= RANDOM(mascot->frame_max[mascot->anime_ptn][mascot->anime_frm] -mascot->frame_min[mascot->anime_ptn][mascot->anime_frm]+1) +mascot->frame_min[mascot->anime_ptn][mascot->anime_frm]; sound_play(mascot,mascot->click_sound[mascot->anime_ptn]); if(mascot->sockmsg){ if(strlen(mascot->sockmsg)>0){ mascot->balseq=0; mascot->bal_mode=BALLOON_DUET; DoBalloon(mascot); flag_balloon=TRUE; } } } } else if (mascot->duet_use_random){ if(mascot->anime_ptn==0){ // ランダムアニメ if(mascot->frame_pix[i_ptn][0]!=-1){ mascot->anime_ptn=i_ptn; mascot->anime_frm=0; } } } }
static gboolean io_callback(GIOChannel * source, GIOCondition condition, gpointer data) { gchar buf[LINE_MAX],tmp[10]; gint fd, readsize; typMascot *mascot = data; gint step,mode,anim,loops; fd = fd_accept(g_io_channel_unix_get_fd(source)); readsize = read(fd, buf, LINE_MAX - 1); buf[readsize] = '\0'; fd_close(fd); // Expiration strncpy(tmp,buf,8); mascot->sockmsg_expire=(gint)(atoi(tmp)/INTERVAL); if(mascot->sockmsg_expire<=0){ mascot->sockmsg_expire=mascot->sockmsg_expire_def/INTERVAL; } // Stepping or Lump Sum? strncpy(tmp,buf+8,2); mode=(gint)atoi(tmp); if(mode<0){ mode=mascot->sockmsg_type; } // Stepping Interval strncpy(tmp,buf+8+2,4); step=(gint)atoi(tmp); if(step<0){ step=mascot->sockmsg_step; } // Play anim strncpy(tmp,buf+8+2+4,4); anim=(gint)atoi(tmp); if(anim<0){ anim=-1; } // Loops strncpy(tmp,buf+8+2+4+4,4); loops=(gint)atoi(tmp); if(loops<-1){ loops=-2; } gchar *message = NULL; #ifdef USE_GTK2 if(mode==SOCK_STEPPING){ message = set_typing_msg(buf+8+2+4+4+4,step); } else{ message = g_strdup(buf+8+2+4+4+4); } #else message = g_strdup(buf+8+2+4+4+4); #endif if(!message) return; int nomsg = 0; if(strcmp(message, "[nostring]") != 0) { if(mascot->sockmsg) g_free(mascot->sockmsg); mascot->sockmsg = message; } else { if(!mascot->sockmsg) { /* there is no old message, we can safely skip * whole balloon thing I guess. * I have really no idea how it works */ nomsg = 2; } else { nomsg = 1; } g_free(message); message = NULL; } if(nomsg != 2) { if(!nomsg) mascot->balseq=0; else mascot->balseq=1; mascot->bal_mode=BALLOON_SOCKMSG; DoBalloon(mascot); flag_balloon = TRUE; } if(anim > 0) { if(anim != mascot->anime_ptn) { mascot->anime_lop=0; mascot->anime_ptn=anim; mascot->anime_frm=0; } } else if( anim == 0 ) { mascot->anime_lop = 0; } if( mascot->anime_ptn != 0 && loops > -2 ) mascot->anime_lop = loops; }
static void low_accept_loop(struct args *arg) { struct args *arg2 = new_args(); ACCEPT_SIZE_T len = sizeof(arg->from); while(1) { MEMCPY(arg2, arg, sizeof(struct args)); arg2->fd = fd_accept(arg->fd, (struct sockaddr *)&arg2->from, &len); if(arg2->fd != -1) { th_farm((void (*)(void *))aap_handle_connection, arg2); arg2 = new_args(); arg2->res.leftovers = 0; } else { if(errno == EBADF) { int i; struct cache_entry *e, *t; struct cache *c, *p = NULL; struct log *l, *n = NULL; /* oups. */ low_mt_lock_interpreter(); /* Can run even if threads_disabled. */ for(i=0; i<CACHE_HTABLE_SIZE; i++) { e = arg->cache->htable[i]; while(e) { t = e; e = e->next; t->next = 0; free_string(t->data); aap_free(t->url); aap_free(t); } } while(arg->log->log_head) { struct log_entry *l = arg->log->log_head->next; aap_free(arg->log->log_head); arg->log->log_head = l; } c = first_cache; while(c && c != arg->cache) { p=c; c = c->next; } if(c) { if(p) p->next = c->next; else first_cache = c->next; c->gone = 1; aap_free(c); } l = aap_first_log; while(l && l != arg->log) { n=l; l = l->next; } if(l) { if(n) n->next = l->next; else aap_first_log = l->next; aap_free(l); } mt_unlock_interpreter(); aap_free(arg2); aap_free(arg); return; /* No more accept here.. */ } } } }