/* ---------------- * index_close - close an index relation * * If lockmode is not "NO_LOCK", we then release the specified lock. * * Note that it is often sensible to hold a lock beyond index_close; * in that case, the lock is released automatically at xact end. * ---------------- */ void index_close(struct relation *relation, lockmode_t lockmode) { struct lock_rel_id relid; relid = relation->rd_lockInfo.lockRelId; ASSERT(lockmode >= NO_LOCK && lockmode < MAX_LOCKMODE); /* The relcache does the real work... */ rel_close(relation); if (lockmode != NO_LOCK) unlock_rel_id(&relid, lockmode); }
int main(int argc, char **argv) { if(argc<3) { fprintf(stderr,"Usage: hw6_receiver <remote host> <base port>\n"); exit(1);} int sock = rel_socket(AF_INET, SOCK_DGRAM, 0); if(sock < 0) { perror("Creating socket failed: "); exit(1); } struct sockaddr_in addr; // internet socket address data structure addr.sin_family = AF_INET; addr.sin_port = htons(atoi(argv[2])+3); // byte order is significant addr.sin_addr.s_addr = INADDR_ANY; int res = bind(sock, (struct sockaddr*)&addr, sizeof(addr)); if(res < 0) { perror("Error binding: "); exit(1); } int starttime = current_msec(); int totalbytes = 0; char segment[MAX_SEGMENT]; while(1) { int recv_count = rel_recv(sock, segment, MAX_SEGMENT); if(recv_count == 0) break; totalbytes+=recv_count; // write out payload to stdout fwrite(segment,1,recv_count,stdout); } int finished_msec = current_msec(); fprintf(stderr,"\nReceived %d bytes in %.4f seconds, %.2f kB/s\n", totalbytes, (finished_msec-starttime)/1000.0, totalbytes/(float)(finished_msec-starttime)); fprintf(stderr, "\nFinished receiving file, closing socket.\n"); rel_close(sock); fflush(stdout); exit(0); }