/** * g_socket_listener_accept_socket_async: * @listener: a #GSocketListener * @cancellable: (allow-none): a #GCancellable, or %NULL * @callback: (scope async): a #GAsyncReadyCallback * @user_data: (closure): user data for the callback * * This is the asynchronous version of g_socket_listener_accept_socket(). * * When the operation is finished @callback will be * called. You can then call g_socket_listener_accept_socket_finish() * to get the result of the operation. * * Since: 2.22 */ void g_socket_listener_accept_socket_async (GSocketListener *listener, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GTask *task; GList *sources; GError *error = NULL; task = g_task_new (listener, cancellable, callback, user_data); if (!check_listener (listener, &error)) { g_task_return_error (task, error); g_object_unref (task); return; } sources = add_sources (listener, accept_ready, task, cancellable, g_main_context_get_thread_default ()); g_task_set_task_data (task, sources, (GDestroyNotify) free_sources); }
/** * g_socket_listener_accept_socket: * @listener: a #GSocketListener * @source_object: (out) (transfer none) (allow-none): location where #GObject pointer will be stored, or %NULL. * @cancellable: (allow-none): optional #GCancellable object, %NULL to ignore. * @error: #GError for error reporting, or %NULL to ignore. * * Blocks waiting for a client to connect to any of the sockets added * to the listener. Returns the #GSocket that was accepted. * * If you want to accept the high-level #GSocketConnection, not a #GSocket, * which is often the case, then you should use g_socket_listener_accept() * instead. * * If @source_object is not %NULL it will be filled out with the source * object specified when the corresponding socket or address was added * to the listener. * * If @cancellable is not %NULL, then the operation can be cancelled by * triggering the cancellable object from another thread. If the operation * was cancelled, the error %G_IO_ERROR_CANCELLED will be returned. * * Returns: (transfer full): a #GSocket on success, %NULL on error. * * Since: 2.22 */ GSocket * g_socket_listener_accept_socket (GSocketListener *listener, GObject **source_object, GCancellable *cancellable, GError **error) { GSocket *accept_socket, *socket; g_return_val_if_fail (G_IS_SOCKET_LISTENER (listener), NULL); if (!check_listener (listener, error)) return NULL; if (listener->priv->sockets->len == 1) { accept_socket = listener->priv->sockets->pdata[0]; if (!g_socket_condition_wait (accept_socket, G_IO_IN, cancellable, error)) return NULL; } else { GList *sources; struct AcceptData data; GMainLoop *loop; if (listener->priv->main_context == NULL) listener->priv->main_context = g_main_context_new (); loop = g_main_loop_new (listener->priv->main_context, FALSE); data.loop = loop; sources = add_sources (listener, accept_callback, &data, cancellable, listener->priv->main_context); g_main_loop_run (loop); accept_socket = data.socket; free_sources (sources); g_main_loop_unref (loop); } if (!(socket = g_socket_accept (accept_socket, cancellable, error))) return NULL; if (source_object) *source_object = g_object_get_qdata (G_OBJECT (accept_socket), source_quark); return socket; }
void substep(struct grid *g, double rkfac1, double rkfac2, double dt, struct parList *pars) { //Calculate gradients of grid quantities calc_grad(g, pars); //Solve Riemann problems. add_fluxes(g, dt, pars); //Add Sources. add_sources(g, dt, pars); //Update prims. calc_prim(g, pars); //Boundary Conditions. bc_1L(g, pars); bc_1R(g, pars); bc_2L(g, pars); bc_2R(g, pars); //Re-update cons. calc_cons(g, pars); }
void got_packet(u_char *args,const struct pcap_pkthdr *header,const u_char *packet) { struct pcap_pkthdr new_header; new_header= *header; int size_ip; //int size_tcp; //int size_udp; //int size_icmp; /*new_header=(struct pcap_pkthdr*)malloc(sizeof(struct pcap_pkthdr*)); new_header->ts=header->ts; new_header->caplen = header->caplen; new_header->len = header->len; */ /* Structures to packet headers */ //const struct sniff_ethernet *ethernet_header; const struct sniff_ip *ip_header; //const struct sniff_tcp *tcp_header; //const struct sniff_udp *udp_header; ip_header=(struct sniff_ip*)(packet + SIZE_ETHERNET); size_ip=IP_HL(ip_header)*4; if (size_ip < 20) { fprintf(stderr," * Invalid IP header length: %u bytes\n", size_ip); return; } if(read_file != NULL) { read_from_file(&new_header); /* free(new_header); */ } if(flag_z == 1) { if(z_value == 2) handleTrack_2(packet); if(z_value == 5) handleTrack_5(packet); } //ethernet_header=(struct sniff_ethernet*)packet; total_count++; /* Determine protocol */ switch(ip_header->ip_p) { case IPPROTO_TCP: count_tcp++; break; case IPPROTO_UDP: count_udp++; break; case IPPROTO_ICMP: count_icmp++; break; case IPPROTO_IP: break; default: count_default++; } total_bytes = total_bytes + header->len; add_sources(packet); /* check for attack */ if(flag_packet==1 || flag_byte==1 /*|| flag_flow==1*/ || flag_source==1) { if(flag_check_attack==1) check_attack(); } }