/* * Write modified pages to disk * * Returns: * 0 == OK * -1 DBM_ERROR */ static int hash_sync(const DB *dbp, uint flags) { HTAB *hashp; if (flags != 0) { errno = EINVAL; return (DBM_ERROR); } if (!dbp) return (DBM_ERROR); hashp = (HTAB *)dbp->internal; if(!hashp) return (DBM_ERROR); if (!hashp->save_file) return (0); if (__buf_free(hashp, 0, 1) || flush_meta(hashp)) return (DBM_ERROR); #if defined(_WIN32) || defined(_WINDOWS) if (hashp->updateEOF && hashp->filename && !hashp->is_temp) { int status = update_EOF(hashp); hashp->updateEOF = 0; if (status) return status; } #endif hashp->new_file = 0; return (0); }
/* * Flushes any changes to the file if necessary and destroys the hashp * structure, freeing all allocated space. */ static int hdestroy(HTAB *hashp) { int i, save_errno; save_errno = 0; #ifdef HASH_STATISTICS (void)fprintf(stderr, "hdestroy: accesses %ld collisions %ld\n", hash_accesses, hash_collisions); (void)fprintf(stderr, "hdestroy: expansions %ld\n", hash_expansions); (void)fprintf(stderr, "hdestroy: overflows %ld\n", hash_overflows); (void)fprintf(stderr, "keys %ld maxp %d segmentcount %d\n", hashp->NKEYS, hashp->MAX_BUCKET, hashp->nsegs); for (i = 0; i < NCACHED; i++) (void)fprintf(stderr, "spares[%d] = %d\n", i, hashp->SPARES[i]); #endif /* * Call on buffer manager to free buffers, and if required, * write them to disk. */ if (__buf_free(hashp, 1, hashp->save_file)) save_errno = errno; if (hashp->dir) { free(*hashp->dir); /* Free initial segments */ /* Free extra segments */ while (hashp->exsegs--) free(hashp->dir[--hashp->nsegs]); free(hashp->dir); } if (flush_meta(hashp) && !save_errno) save_errno = errno; /* Free Bigmaps */ for (i = 0; i < hashp->nmaps; i++) if (hashp->mapp[i]) free(hashp->mapp[i]); if (hashp->tmp_key) free(hashp->tmp_key); if (hashp->tmp_buf) free(hashp->tmp_buf); if (hashp->fp != -1) { (void)_fsync(hashp->fp); (void)_close(hashp->fp); } free(hashp); if (save_errno) { errno = save_errno; return (ERROR); } return (SUCCESS); }
bool send_tcppacket(connection_t *c, const vpn_packet_t *packet) { /* If there already is a lot of data in the outbuf buffer, discard this packet. We use a very simple Random Early Drop algorithm. */ if(2.0 * c->outbuflen / (float)maxoutbufsize - 1 > (float)rand()/(float)RAND_MAX) return true; if(!send_request(c, "%d %hd", PACKET, packet->len)) return false; return send_meta(c, (char *)packet->data, packet->len) && flush_meta(c); }
/* * Write modified pages to disk * * Returns: * 0 == OK * -1 ERROR */ static int hash_sync(const DB *dbp, u_int32_t flags) { HTAB *hashp; if (flags != 0) { errno = EINVAL; return (ERROR); } if (!dbp) return (ERROR); hashp = (HTAB *)dbp->internal; if (!hashp->save_file) return (0); if (__buf_free(hashp, 0, 1) || flush_meta(hashp)) return (ERROR); hashp->new_file = 0; return (0); }
/* check all connections to see if anything happened on their sockets */ static void check_network_activity(fd_set * readset, fd_set * writeset) { connection_t *c; avl_node_t *node; int result, i; socklen_t len = sizeof(result); vpn_packet_t packet; static int errors = 0; /* check input from kernel */ if(device_fd >= 0 && FD_ISSET(device_fd, readset)) { if(devops.read(&packet)) { if(packet.len) { errors = 0; packet.priority = 0; route(myself, &packet); } } else { usleep(errors * 50000); errors++; if(errors > 10) { logger(LOG_ERR, "Too many errors from %s, exiting!", device); running = false; } } } /* check meta connections */ for(node = connection_tree->head; node; node = node->next) { c = node->data; if(c->status.remove) continue; if(FD_ISSET(c->socket, writeset)) { if(c->status.connecting) { c->status.connecting = false; getsockopt(c->socket, SOL_SOCKET, SO_ERROR, (void *)&result, &len); if(!result) finish_connecting(c); else { ifdebug(CONNECTIONS) logger(LOG_DEBUG, "Error while connecting to %s (%s): %s", c->name, c->hostname, sockstrerror(result)); closesocket(c->socket); do_outgoing_connection(c); continue; } } if(!flush_meta(c)) { terminate_connection(c, c->status.active); continue; } } if(FD_ISSET(c->socket, readset)) { if(!receive_meta(c)) { terminate_connection(c, c->status.active); continue; } } } for(i = 0; i < listen_sockets; i++) { if(FD_ISSET(listen_socket[i].udp, readset)) handle_incoming_vpn_data(i); if(FD_ISSET(listen_socket[i].tcp, readset)) handle_new_meta_connection(listen_socket[i].tcp); } }