/*====================================== * CORE : Connection functions *--------------------------------------*/ int connect_client(int listen_fd) { int fd; struct sockaddr_in client_address; socklen_t len; len = sizeof(client_address); fd = sAccept(listen_fd, (struct sockaddr*)&client_address, &len); if ( fd == -1 ) { ShowError("connect_client: accept failed (%s)!\n", error_msg()); return -1; } if( fd == 0 ) { // reserved ShowError("connect_client: Socket #0 is reserved - Please report this!!!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) { // socket number too big ShowError("connect_client: New socket #%d is greater than can we handle! Increase the value of FD_SETSIZE (currently %d) for your OS to fix this!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd,0); set_nonblocking(fd, 1); #ifndef MINICORE if( ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr)) ) { do_close(fd); return -1; } #endif if( fd_max <= fd ) fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); return fd; }
/*====================================== * CORE : Connection functions *--------------------------------------*/ int connect_client(int listen_fd) { int fd; struct sockaddr_in client_address; socklen_t len; len = sizeof(client_address); fd = sAccept(listen_fd, (struct sockaddr*)&client_address, &len); if ( fd == -1 ) { ShowError("connect_client: accept falhou (codigo %d)!\n", sErrno); return -1; } if( fd == 0 ) {// reserved ShowError("connect_client: Socket #0 e reservado - Favor reportar isso!!!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) {// socket number too big ShowError("connect_client: Novo socket #%d e maior do que suportamos! aumente o valor de FD_SETSIZE (atualmente %d) para seu SO consertar isso!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd); set_nonblocking(fd, 1); #ifndef MINICORE if( ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr)) ) { do_close(fd); return -1; } #endif if( fd_max <= fd ) fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); return fd; }
/*====================================== * CORE : Connection functions *--------------------------------------*/ int connect_client(int listen_fd) { int fd; struct sockaddr_in client_address; socklen_t len; len = sizeof(client_address); fd = sAccept(listen_fd, (struct sockaddr *)&client_address, &len); if(fd == -1) { ShowError(read_message("Source.common.connect_client"), error_msg()); return -1; } if(fd == 0) { // reserved ShowError(read_message("Source.common.connect_client2")); sClose(fd); return -1; } if(fd >= FD_SETSIZE) { // socket number too big ShowError(read_message("Source.common.connect_client3"), fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd); set_nonblocking(fd, 1); #ifndef MINICORE if(ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr))) { do_close(fd); return -1; } #endif if(fd_max <= fd) fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); return fd; }
/*====================================== * CORE : Connection functions *--------------------------------------*/ int connect_client(int listen_fd) { int fd; struct sockaddr_in client_address; socklen_t len; len = sizeof(client_address); fd = sAccept(listen_fd, (struct sockaddr*)&client_address, &len); if ( fd == -1 ) { ShowError("connect_client: Recebimento falhou (%s)!\n", error_msg()); return -1; } if( fd == 0 ) { // reserved ShowError("connect_client: Socket #0 esta reservado - Por favor reporte isso!!!\n"); sClose(fd); return -1; } if( fd >= FD_SETSIZE ) { // socket number too big ShowError("connect_client: Novo socket #%d e maior do que o limite suportado! Aumentando o valor para FD_SETSIZE (atualmente %d) seu SO deve corrigir isso!\n", fd, FD_SETSIZE); sClose(fd); return -1; } setsocketopts(fd,NULL); set_nonblocking(fd, 1); #ifndef MINICORE if( ip_rules && !connect_check(ntohl(client_address.sin_addr.s_addr)) ) { sockt->close(fd); return -1; } #endif if( sockt->fd_max <= fd ) sockt->fd_max = fd + 1; sFD_SET(fd,&readfds); create_session(fd, recv_to_fifo, send_from_fifo, default_func_parse); session[fd]->client_addr = ntohl(client_address.sin_addr.s_addr); return fd; }
static gboolean expose_event (GtkWidget *widget, GdkEventExpose *event) { widget_data_t *data = get_widget_data(widget); designer_node_t *hn = NULL; _hit_t hit; int hs = -1; cairo_t *cr = gdk_cairo_create( GTK_WIDGET (data->drawing_area)->window); cairo_set_source_rgb(cr, 0.9, 0.9, 0.9); cairo_paint(cr); _size_t delta = _ptos(data->visible_area.o); cairo_translate(cr, 0.5 - delta.w, 0.5 - delta.h); #if 0 cairo_set_line_width(cr, 3.0); cairo_set_source_rgba(cr, 0.3, 0.3, 0.3, 0.5); round_path(cr, data->used_area, round_s); cairo_stroke(cr); cairo_set_source_rgba(cr, 0.8, 0.6, 0.3, 0.5); round_path(cr, data->visible_area, round_s); cairo_stroke(cr); { char buf[32]; _point_t o = data->mouse; show_axis(cr, o, 0,0,0, 20, 20); set_title_font(cr); cairo_set_source_rgba(cr, 1.0, 0.0, 0.0, 0.8); cairo_move_to(cr, o.x + 5, o.y - 5); sprintf(buf, "(%.0f,%.0f)", o.x, o.y); cairo_show_text(cr, buf); cairo_stroke(cr); cairo_move_to(cr, o.x + 5, o.y + 13); sprintf(buf, "[%.0f,%.0f,%.0fx%.0f]", data->used_area.o.x, data->used_area.o.y, data->used_area.s.w, data->used_area.s.h); cairo_show_text(cr, buf); cairo_stroke(cr); cairo_move_to(cr, o.x + 5, o.y + 28); sprintf(buf, "[%.0f,%.0f,%.0fx%.0f]", data->visible_area.o.x, data->visible_area.o.y, data->visible_area.s.w, data->visible_area.s.h); cairo_show_text(cr, buf); cairo_stroke(cr); show_axis(cr, _zerop, 1,0,0, 10, 10); } #endif /* draw the slot conenctions */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *dst = list->data; node_data_t *ndd = node_data(dst); calc_node_type(cr, dst->type); calc_node(cr, dst); for (GSList *slot_list = dst->input_slots; slot_list != NULL; slot_list = slot_list->next) { designer_slot_t *slot = slot_list->data; designer_node_t *src = slot->source; node_data_t *nsd = node_data(src); designer_slot_spec_t *src_spec = slot->output_slot_spec; designer_slot_spec_t *dst_spec = slot->input_slot_spec; slot_spec_data_t *ssd = slot_spec_data(src_spec); slot_spec_data_t *dsd = slot_spec_data(dst_spec); _point_t sp = _move(_move(nsd->or.o, _ptos(nsd->origin)), ssd->offset); _point_t dp = _move(_move(ndd->ir.o, _ptos(ndd->origin)), dsd->offset); draw_connect(cr, sp, dp, 0); } /* check for 'highest' node hit */ _hit_t nht = hit_node(dst, data->mouse); if (nht) { hn = dst; hit = nht; } } /* update target info */ switch (hit) { case HIT_INPUT: hs = hit_input_slot(hn, data->mouse); data->target = input_slot_origin(hn, hs); if (data->state == STATE_IDLE) /* show 'break' if already connected */ data->target_check = input_slot_check(hn, hs); else if (data->state == STATE_CONIN) data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; else if (data->state == STATE_CONOUT && ((hn != data->target_node) || (hs != data->target_slot_id))) data->target_check = connect_check( data->active_node, data->active_slot_id, hn, hs); break; case HIT_OUTPUT: hs = hit_output_slot(hn, data->mouse); data->target = output_slot_origin(hn, hs); if (data->state == STATE_IDLE) data->target_check = DESIGNER_CONNECTION_FREE; else if (data->state == STATE_CONOUT) data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; else if (data->state == STATE_CONIN && ((hn != data->target_node) || (hs != data->target_slot_id))) data->target_check = connect_check( hn, hs, data->active_node, data->active_slot_id); break; default: data->target_check = DESIGNER_CONNECTION_UNCONNECTABLE; hs = -1; break; } data->target_node = hn; data->target_slot_id = hs; /* draw the nodes */ for (GSList *list = data->design->nodes; list != NULL; list = list->next) { designer_node_t *node = list->data; int flags = (node == data->design->root) ? 0x1 : 0; draw_node(cr, node, flags); if (node == hn) { draw_highlight(cr, node, data->mouse, hit, data->target_check); } } if (data->state == STATE_CONIN) { draw_connect(cr, data->mouse, data->origin, 0); } if (data->state == STATE_CONOUT) { draw_connect(cr, data->origin, data->mouse, 0); } cairo_destroy(cr); return FALSE; }
int func_getVertexConnectivity(struct adjacent_info ai){ int i,j,k; int l=0; int m=0; int v[8]; int total; int vertexConnectivity; int **matrix; int **adjacent_copy = NULL; struct NODE *root; int count; //点集合リスト作成 root = (struct NODE *)malloc(sizeof(struct NODE)); root->value = 0; root->next = NULL; //点集合vの初期化 for(i=0;i < ai.numPoint;i++) v[i] = 0; for(i = 1; i<256;i++){ //隣接行列の初期化2(隣接行列をいじるので,初期化を繰り返す必要がある) adjacent_copy = func_cpyMatrix(ai.adjacent,ai.numPoint,ai.numPoint); total = 0; for(j = 0; j < 8;j++){ //val % 2^(j+1) / 2^j の部分 v[j] = i%power(2,j+1)/power(2,j); //printf("%d % power(2,%d+1) = %d , ,v[j] = %d\n",i,j , i%power(2,j+1),i%power(2,j+1)/power(2,j)); total += v[j]; } matrix = func_Make_MN_Matrix(ai.numPoint - total,ai.numPoint - total); //消される点を全て-1に置き換える for(j = 0;j < ai.numPoint;j++) if(v[j] == 1) for(k=0;k<ai.numPoint;k++){ adjacent_copy[j][k] = -1; adjacent_copy[k][j] = -1; } /* for(j = 0;j < ai.numPoint;j++){ for(k = 0; k <ai.numPoint;k++) printf(" %d",adjacent_copy[j][k]); printf("\n"); } printf("-----------------------------------------\n"); */ //点が-1の場合,その点を消し,その点以外の点で新しい行列を作る l=0; for(j = 0; j < ai.numPoint;j++){ count = 0; for(k = 0; k <ai.numPoint;k++){ if(adjacent_copy[j][k] != -1){ matrix[l][m] = adjacent_copy[j][k]; m++; count++; } } m=0; if(count > 0) l++; } /* for(j = 0;j < ai.numPoint - total;j++){ for(k = 0; k <ai.numPoint - total;k++) printf(" %d",matrix[j][k]); printf("\n"); } */ //連結か非連結かを確かめる if(connect_check(ai.numPoint-total,matrix) > 1){ func_addValueToList(total,root); //func_printList(root); } func_freeMatrix(matrix,ai.numPoint - total,ai.numPoint - total); func_freeMatrix(adjacent_copy,ai.numPoint,ai.numPoint); // use_getrusage(); } //func_printList(root); vertexConnectivity = func_getMinimumFromList(root); printf("点連結度は%dです",vertexConnectivity); func_freeList(root); use_getrusage(); return vertexConnectivity; }
static int connect_client(int listen_fd) { int fd; struct sockaddr_in client_address; #ifdef __WIN32 int len; #else socklen_t len; #endif //ShowMessage("connect_client : %d\n",listen_fd); len=sizeof(client_address); fd = accept(listen_fd,(struct sockaddr*)&client_address,&len); #ifdef __WIN32 if (fd == SOCKET_ERROR || fd == INVALID_SOCKET || fd < 0) { ShowError("accept failed (code %d)!\n", fd, WSAGetLastError()); return -1; } #else if(fd==-1) { perror("accept"); return -1; } #endif if(fd_max<=fd) fd_max=fd+1; setsocketopts(fd); #ifdef __WIN32 { unsigned long val = 1; if (ioctlsocket(fd, FIONBIO, &val) != 0) ShowError("Nao e necessario ajustar o soquete � modalidade non-blocking (code %d)!\n", WSAGetLastError()); } #else if (fcntl(fd, F_SETFL, O_NONBLOCK) == -1) perror("connect_client (set nonblock)"); #endif if (ip_rules && !connect_check(*(unsigned int*)(&client_address.sin_addr))) { do_close(fd); return -1; } else FD_SET(fd,&readfds); CREATE(session[fd], struct socket_data, 1); CREATE_A(session[fd]->rdata, unsigned char, rfifo_size); CREATE_A(session[fd]->wdata, unsigned char, wfifo_size); session[fd]->max_rdata = (int)rfifo_size; session[fd]->max_wdata = (int)wfifo_size; session[fd]->func_recv = recv_to_fifo; session[fd]->func_send = send_from_fifo; session[fd]->func_parse = default_func_parse; session[fd]->client_addr = client_address; session[fd]->rdata_tick = last_tick; session[fd]->type = SESSION_UNKNOWN; // undefined type //ShowMessage("new_session : %d %d\n",fd,session[fd]->eof); return fd; }