資源簡介
olfile readme file.
[1. 文件名解釋]
olfile: Offload File
這個工具原本是項目中為測試TOE引擎的效率而設計的,
可以作為socket編程的一個例子來學習。
[2. 文件介紹]
程序中使用socket實現了文件的傳輸。
在VC6.0中編譯通過,目錄中olfile.cpp/olfile.h是原文件,可以任意修改,不過請不要改動文件頭的作者信息。
有兩個目錄:server、client,其實編譯出來的東西是一樣的,當時是為了測試方便才分出來的。
可以直接打開client目錄中的工程來編譯。
[3. 使用介紹]
程序分client端和server端,server 端監聽,client端使用命令行方式發送或接收文件。
在VC6.0中編譯生成olfile.exe,使用不同的選項啟動client和server。
比如,我們有兩臺機器10.190.1.1(A), 10.190.1.2(B),加入都運行windows,想把A的c:foo.dat傳到B,并放在B的c:foodst.dat,
則需要在B啟動server:
olfile -server
A啟動client進行傳輸:
o
lfile -src c:foo.dat -dst c:foodst.dat -ip 10.190.1.2 -y
-src 表示源文件的位置
-dst 表示目標文件的位置
-ip 表示遠程主機的IP。
-y 表示如果遠程主機上的目標文件位置原來有文件,則強制覆蓋。
可以看出,可以讓A當作Server,B當作Client,使用不同的命令行實現上面的文件傳遞:
A啟動server:
olfile -server
B啟動client 進行文件傳輸,這時B的c:foodst.dat是目標:
olfile -dst c:foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[4.兼容性]
附帶的Makefile文件表明,代碼可以在Linux下正常編譯。所以,可以運行在Linux下,實現Linux與Windows文件的互傳。
可能的命令行會變成:
olfile -dst /home/foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[5. 局限和可能存在的問題]
1.程序不會對你所使用的系統產生致命影響,因為它僅僅是一個socket 實例。
2.server 在進行一次文件傳輸之后就退出,因為程序是單一線程的。
3.可以利用程序的打印輸出看一下大概的傳輸速度(因為這時我當時在項目中寫這個工具的原因)。
[1. 文件名解釋]
olfile: Offload File
這個工具原本是項目中為測試TOE引擎的效率而設計的,
可以作為socket編程的一個例子來學習。
[2. 文件介紹]
程序中使用socket實現了文件的傳輸。
在VC6.0中編譯通過,目錄中olfile.cpp/olfile.h是原文件,可以任意修改,不過請不要改動文件頭的作者信息。
有兩個目錄:server、client,其實編譯出來的東西是一樣的,當時是為了測試方便才分出來的。
可以直接打開client目錄中的工程來編譯。
[3. 使用介紹]
程序分client端和server端,server 端監聽,client端使用命令行方式發送或接收文件。
在VC6.0中編譯生成olfile.exe,使用不同的選項啟動client和server。
比如,我們有兩臺機器10.190.1.1(A), 10.190.1.2(B),加入都運行windows,想把A的c:foo.dat傳到B,并放在B的c:foodst.dat,
則需要在B啟動server:
olfile -server
A啟動client進行傳輸:
o
lfile -src c:foo.dat -dst c:foodst.dat -ip 10.190.1.2 -y
-src 表示源文件的位置
-dst 表示目標文件的位置
-ip 表示遠程主機的IP。
-y 表示如果遠程主機上的目標文件位置原來有文件,則強制覆蓋。
可以看出,可以讓A當作Server,B當作Client,使用不同的命令行實現上面的文件傳遞:
A啟動server:
olfile -server
B啟動client 進行文件傳輸,這時B的c:foodst.dat是目標:
olfile -dst c:foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[4.兼容性]
附帶的Makefile文件表明,代碼可以在Linux下正常編譯。所以,可以運行在Linux下,實現Linux與Windows文件的互傳。
可能的命令行會變成:
olfile -dst /home/foodst.dat -src c:foo.dat -ip 10.190.1.1 -y
[5. 局限和可能存在的問題]
1.程序不會對你所使用的系統產生致命影響,因為它僅僅是一個socket 實例。
2.server 在進行一次文件傳輸之后就退出,因為程序是單一線程的。
3.可以利用程序的打印輸出看一下大概的傳輸速度(因為這時我當時在項目中寫這個工具的原因)。
代碼片段和文件信息
??????????????????????????????????
/**
Offload?file?transfer?module?using?socket?to?test?TCP?offload?engine(TOE).
By?Vino?@?9th?June?2004.
Email:?rtc@eyou.com
All?copyrights?reserved.
*/
#include?
#include?
#include?
#include?
#include?
#include?
#ifdef?WIN32
#include?
#include?
#else
#include?
#include?
#include?
#include?
#include?
#endif
#include?
#include?“olfile.h“
const?char?str_usg[]?=?
“\nTransfer?a?file?from?data?source?to?data?sink?through?network.\n\n“
“??olfile?-src?sourcefile?-snk?sinkfile?-ip?dotip?[-y]\n“
“?????Copy?sourcefile?on?local?to?sinkfile?on?ip?dotip.\n\n“
“??olfile?-snk?sinkfile?-src?sourcefile?-ip?dotip?[-y]\n“
“?????Copy?sourcefile?on?ip?dotip?to?sinkfile?on?local.\n\n“
“??olfile?-server\n“
“?????Start?olfile?service.\n\n“
“Options:\n“
“????-src?+?sourcefile??????Data?source?file?full?path\n“
“????-snk?+?sinkfile????????Data?sink?file?full?path\n“
“????-ip??+?dotip???????????Dot?divided?ip?address\n“
“????-y?????????????????????Default?to?delete?exists?file.\n\n“
“Example:\n“
“?????-snk?f:/data.txt?-src?f:/datarcv.txt?-ip?10.190.5.179?-y\n\n“
“By?Vino.Cui?@?9th?June?2004?from?Inventec.\n“
“Revision:\n“
“1.?13th?June?2004?Completed?the?original?version:?Transfering?file?\nfrom?data?source?to?data?sink?via?ip?specified?by?-ip?argument.?\n“;
const?size_t?OP_HEAD_SIZE?=?sizeof(struct?st_op_head);
struct?st_reg_sem?s_reg_sem;
/**?these?4?buffer?pools?are?dynamic?allocated?in?the?program.
??file?->?read-File?Buffer?Pool?->?send-NIC?Buffer?Pool?->?NIC
??file?<-?write-File?Buffer?Pool?<-?receive-NIC?Buffer?Pool?<-?NIC
but?this?implementation?needs?buffer?copy(copy?read-file?Buffer?to?send-NIC?Buffer?pool?and?back-forth).
??char?*rdFileBufPool?*wrFileBufPool;
??char?*sendNicBufPool?*recvNicBufPool;
*/
char?*lanin_buf?*lanout_buf;
char?*gfin_buf?*gfout_buf;
float?ftop_spd?=?0.0;?//?top?speed?bytes/s
/***/
int
init_socket()
{
#ifdef?WIN32
WSADATA?wsaData;
int?iResult?=?WSAStartup(MAKEWORD(22)?&wsaData);
if?(iResult?!=?NO_ERROR)
{
printf(“Error?at?WSAStartup()\n“);
return?-1;
}
return?0;
#else
return?0;
#endif
}
int
create_conn(){
SOCKET?s;
struct?sockaddr_in?local;
BOOL?bOptVal?=?TRUE;
int?bOptLen?=?sizeof(BOOL);
int?iOptLen?=?sizeof(int);
if((s?=?socket(AF_INET_NORMAL?SOCK_STREAM?0))?==?-1){
perror(“socket“);
return?-1;
}
int?a=?setsockopt(s?SOL_SOCKET?SO_REUSEADDR?(char*)&bOptVal?bOptLen);
memset(&(local)?0?sizeof(struct?sockaddr_in));
local.sin_family?=?AF_INET;??????/*?host?byte?order?*/
local.sin_port?=?htons(SERVER_PORT);
local.sin_addr.s_addr?=?INADDR_ANY;
if?(?-1?==?bind(s?(struct?sockaddr*)&local?sizeof(struct?sockaddr))?)
{
fprintf(stderr?“bind?error\n“);
show_err();
return?(-1);
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄??????????0??2004-06-25?12:08??client
?????文件??????58368??2004-07-07?13:13??client\olfile.ncb
?????文件???????1270??2004-07-07?13:13??client\olfile.plg
?????文件???????4425??2004-06-13?16:10??client\olfile.dsp
?????文件??????54784??2004-06-17?14:10??client\olfile.opt
?????文件????????535??2004-07-07?13:12??client\olfile.dsw
?????目錄??????????0??2004-06-25?12:07??server
?????文件????????537??2004-06-10?11:42??server\olfiled.dsw
?????文件??????58368??2004-06-17?13:43??server\olfiled.ncb
?????文件???????1300??2004-06-17?13:31??server\olfiled.plg
?????文件???????4436??2004-06-13?16:10??server\olfiled.dsp
?????文件??????54784??2004-06-17?13:43??server\olfiled.opt
?????文件????????727??2004-06-25?11:08??Makefile
?????文件??????31205??2004-07-07?13:14??olfile.cpp
?????文件???????4116??2004-07-07?13:14??olfile.h
?????文件???????1725??2004-07-07?13:31??readme.txt
?????文件???????3189??2004-04-19?10:52??代碼中國.txt
?????文件????????126??2004-04-03?17:45??代碼中國.url
?????文件???????3930??2003-11-05?18:50??說明.htm
-----------?---------??----------?-----??----
???????????????283825????????????????????19
評論
共有 條評論