?? mcast-srv.c
字號:
/* mcast-srv.c -- multicasting server main thread * * This file is part of 'netcast' program, released under BSD License. * (c) 2001-2002 Stanis砤w Pa秌o <staszek@nutki.com>. All rights reserved. */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <sys/types.h>#include <sys/socket.h>#include <pthread.h>#include <signal.h>#include "mdist.h"#include "mcast.h"#include "util.h"#include "server.h"void *mcast_srv_main(void *args) { struct sockaddr_in sin; /* endpoint address */ int ms,i; /* multicast socket */ struct sempack *msp; /* Sync with TCP */ char adr[128]; long long total=0; int start,now; float speed; /* Open some random multicast group */ msp = (struct sempack *) args; srand(time(0)); sprintf(adr,"%s%d",MCAST_ADDR_BASE,rand()%254+1); sin = make_addr(adr,server_port); mdini.group = sin; ms = init_mcast_socket(&sin); md_init(); /* Let TCP servers accept connections */ V(msp->init); P(msp->accept); MSG(7,"All your bases are belong to us."); start=time(0); do { /* Read data from stdin */ i = md_fill(0); if (!client_count) { i=0; mdhead.pkt=0; } MSG(7,"Lower your shields and surrender your ships."); /* tcp: Send headers */ V(msp->prepare); P(msp->ready); /* multicast data */ while (i--) sendto(ms,mdbuf[i],mdbuf[i]->siz+sizeof(struct mdmsg),0,(struct sockaddr *)&sin,sizeof(sin)); MSG(7,"Your biological distinctiveness will serve us."); /* tcp: Send end-of-data marks */ V(msp->prepare); P(msp->finish); now=time(0); total=total+mdhead.siz; speed=(((float)total)/(1024*1024))/((float) now-start); fprintf(stderr,"\rnetcast: sent %lld bytes in %d secs at %.3f MBps", total,now-start,speed); } while (mdhead.pkt); /* fin. */ MSG(7,"Resistance is futile. You shall be assimilated."); fprintf(stderr,"\nnetcast: done.\n"); return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -