• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

oga's tools


コミットメタ情報

リビジョン2fb4c426c0fdd6dcca2d197a8e3c9201b0a18c96 (tree)
日時2016-01-19 06:45:17
作者oga <oga@mxg....>
コミッターoga

ログメッセージ

fix windows code

変更サマリ

差分

--- a/netpf_send.c
+++ b/netpf_send.c
@@ -9,6 +9,7 @@
99 * 03/06/07 V1.02 diff 0 対策
1010 * -------------------------------
1111 * 16/01/14 V1.03 netpf.c => netpf_send.c
12+ * 16/01/19 V1.04 add shutdown for win 10054 error
1213 */
1314 #include <stdio.h>
1415 #include <stdlib.h>
@@ -16,6 +17,7 @@
1617 #include <errno.h>
1718
1819 #ifdef DOS
20+#include <windows.h>
1921 #include <winsock.h>
2022 #else /* DOS */
2123 #include <sys/types.h>
@@ -29,15 +31,26 @@
2931 #include <signal.h>
3032 #endif /* DOS */
3133
32-#define LOOP 3
34+#define VER "1.04"
35+#define LOOP 3
3336 #define dprintf
37+#define SEND_SIZE (1024*1024*10) /* default: 10MB */
38+
39+#ifndef SHUT_RDWR
40+#define SHUT_RDWR SD_BOTH
41+#endif
42+
43+#ifndef SD_BOTH
44+#define SD_BOTH 0x02
45+#endif
3446
3547 void PUT_DATA(int, char *, int);
3648 void GET_DATA(int, char *, int);
3749 void reapchild();
3850 void memdump(FILE *, unsigned char *, int);
3951
40-int SEND_SIZE = (1024*1024*10); /* default: 2MB */
52+int send_size = SEND_SIZE; /* default: 10MB */
53+int vf = 0; /* verbose */
4154
4255 #ifdef DOS
4356 /*
@@ -59,7 +72,6 @@ char *b[];
5972 struct hostent *hostp;
6073 int fd;
6174 int con = 0;
62- int vf = 0;
6375 int port = 22122;
6476 int sz, i;
6577 int svf = 0; /* for client process */
@@ -72,6 +84,7 @@ char *b[];
7284
7385 for (i = 1; i<a; i++) {
7486 if (!strncmp(b[i],"-h",2)) {
87+ printf("netpf_send ver%s\n", VER);
7588 printf("usage : netpf_send { -s | <hostname> } [-p <port(%d)>] [-c <send_size(MB)>\n", port);
7689 printf(" -s : start as netpf server\n");
7790 printf(" hostnames : netpf server name.(start as netpf client)\n");
@@ -89,7 +102,7 @@ char *b[];
89102 continue;
90103 }
91104 if (!strncmp(b[i],"-c",2)) {
92- SEND_SIZE = atoi(b[++i])*1024*1024;
105+ send_size = atoi(b[++i])*1024*1024;
93106 continue;
94107 }
95108 if (!strncmp(b[i],"-v",2)) {
@@ -99,7 +112,7 @@ char *b[];
99112 strcpy(hostn,b[i]);
100113 }
101114
102- if (!(buf = (char *)malloc(SEND_SIZE))) {
115+ if (!(buf = (char *)malloc(send_size))) {
103116 printf("malloc error. errno=%d\n",errno);
104117 exit(1);
105118 }
@@ -178,13 +191,19 @@ char *b[];
178191 printf("accept %d pid=%d\n",con,getpid());
179192 /* サーバ処理 */
180193 for (i = 0; i<LOOP; i++) {
181- printf("## recv %d MB start\n",SEND_SIZE/1024/1024);
182- GET_DATA(newsockfd, buf, SEND_SIZE);
183- //printf("## send %d KB start\n",SEND_SIZE/1024);
184- //PUT_DATA(newsockfd, buf, SEND_SIZE);
194+ printf("## recv %d MB start\n",send_size/1024/1024);
195+ GET_DATA(newsockfd, buf, send_size);
196+ //printf("## send %d KB start\n",send_size/1024);
197+ //PUT_DATA(newsockfd, buf, send_size);
185198 }
186- printf("chile pid=%d exit!\n",getpid());
187- shutdown (newsockfd, SHUT_RDWR);
199+ printf("chile pid=%d exit!\n",getpid());
200+ if (shutdown(newsockfd, SHUT_RDWR) < 0) {
201+#ifdef DOS
202+ printf("send: errno=%d LastErr=%d\n", errno, WSAGetLastError());
203+#else
204+ printf("send: errno=%d\n", errno);
205+#endif
206+ }
188207 close(newsockfd);
189208 #ifndef DOS
190209 exit(0);
@@ -238,12 +257,18 @@ char *b[];
238257 exit(-1);
239258 }
240259 for (i = 0; i<LOOP; i++) {
241- printf("## send %d MB start\n",SEND_SIZE/1024/1024);
242- PUT_DATA(sockfd, buf, SEND_SIZE);
243- //printf("## recv %d MB start\n",SEND_SIZE/1024/1024);
244- //GET_DATA(sockfd, buf, SEND_SIZE);
260+ printf("## send %d MB start\n",send_size/1024/1024);
261+ PUT_DATA(sockfd, buf, send_size);
262+ //printf("## recv %d MB start\n",send_size/1024/1024);
263+ //GET_DATA(sockfd, buf, send_size);
245264 }
246- shutdown (sockfd, SHUT_RDWR);
265+ if (shutdown(sockfd, SHUT_RDWR) < 0) {
266+#ifdef DOS
267+ printf("send: errno=%d LastErr=%d\n", errno, WSAGetLastError());
268+#else
269+ printf("send: errno=%d\n", errno);
270+#endif
271+ }
247272 close(sockfd);
248273
249274 }
@@ -258,12 +283,14 @@ void PUT_DATA(int sockfd, char *buf, int sz)
258283 int size, all=0;
259284 struct timeval tv, tv2;
260285 unsigned int wk,wk2,diff;
286+ int cnt = 0;
261287
262288 gettimeofday(&tv,0);
263289 wk = tv.tv_sec*1000000 + tv.tv_usec;
264290 dprintf("Send start usec : %u\n",wk);
265291
266292 do {
293+ ++cnt;
267294 size = send(sockfd, buf, sz-all, 0);
268295 if (size < 0) {
269296 #ifdef DOS
@@ -276,13 +303,17 @@ void PUT_DATA(int sockfd, char *buf, int sz)
276303 all += size;
277304 } while (all < sz);
278305
306+ if (vf) {
307+ printf("num of send = %d\n", cnt);
308+ }
309+
279310 gettimeofday(&tv,0);
280311 wk2 = tv.tv_sec*1000000 + tv.tv_usec;
281312 diff = wk2-wk;
282313 if (diff <0 ) diff = -diff;
283314 dprintf("Send end usec : %u\n",wk2);
284315 dprintf(" diff usec : %u\n",diff);
285- printf("Send Size = %d time = %.3fsec perf = %.3MB/sec\n",
316+ printf("Send Size = %d time = %.3fsec perf = %.3fMB/sec\n",
286317 all,
287318 (float)diff/1000000,
288319 (diff/1000 == 0)?999999:(float)all/diff); /* V1.02-C */
@@ -300,12 +331,14 @@ void GET_DATA(int sockfd, char *buf, int sz)
300331 int size, all=0;
301332 struct timeval tv, tv2;
302333 unsigned int wk,wk2,diff;
334+ int cnt = 0;
303335
304336 gettimeofday(&tv,0);
305337 wk = tv.tv_sec*1000000 + tv.tv_usec;
306338 dprintf("Recv start usec : %u\n",wk);
307339
308340 do {
341+ ++cnt;
309342 size = recv(sockfd, buf, sz-all, 0);
310343 if (size < 0) {
311344 #ifdef DOS
@@ -318,6 +351,10 @@ void GET_DATA(int sockfd, char *buf, int sz)
318351 all += size;
319352 } while (all < sz);
320353
354+ if (vf) {
355+ printf("num of recv = %d\n", cnt);
356+ }
357+
321358 gettimeofday(&tv,0);
322359 wk2 = tv.tv_sec*1000000 + tv.tv_usec;
323360 diff = wk2-wk;