Commit 08249cb90ef1f5e24da7c4d1141b37ed112aef78

Authored by David RENE
1 parent a737dc7b

the ftp return a Maybe(One)

Showing 1 changed file with 23 additions and 22 deletions   Show diff stats
calexium_lib/net_services_protocols/ftp_client.anubis
... ... @@ -13,9 +13,10 @@ read calexium_lib/net_services/CXM_generic_protocol.anubis
13 13 read system/message_queue.anubis
14 14 read system/message_transceiver.anubis
15 15 read system/muscle.anubis
  16 +read system/files.anubis
16 17 read tools/basis.anubis
17 18  
18   -define One
  19 +define Maybe(One)
19 20 receive_data
20 21 (
21 22 MessageQueue mQ,
... ... @@ -26,22 +27,22 @@ define One
26 27 //println("receive_data ");
27 28 if mQ.get_next_received_Message(30) is
28 29 {
29   - timeout then unique,
30   - closed then unique,
  30 + timeout then failure,
  31 + closed then failure,
31 32 msg(_msg) then
32 33 with last_block = if find_bool(_msg, "End") is {failure then false, success(r) then r},
33 34 if find_raw(_msg, "Data") is
34 35 {
35   - failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA),
  36 + failure then println("Can't find raw Data"); send_ACK_error(mQ, _CXM_FTP_DATA); failure,
36 37 success(data) then
37 38 if write(fd, data) is
38 39 {
39   - failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA),
  40 + failure then println("Can't write into file"); send_ACK_error(mQ, _CXM_FTP_DATA);failure,
40 41 success(len) then
41 42 send_ACK_ok(mQ, _CXM_FTP_DATA);
42 43 if last_block then
43 44 println("File received successfully");
44   - unique
  45 + success(unique)
45 46 else
46 47 println("Bytes received : " + (so_far + len));
47 48 receive_data(mQ, fd, so_far + len, left_read - len)
... ... @@ -50,16 +51,17 @@ define One
50 51 }
51 52 .
52 53  
53   -define One
  54 +define Maybe(One)
54 55 start_get_file_transtert
55 56 (
56 57 MessageQueue mQ,
57 58 String local_file,
58 59 Int32 size
59 60 )=
  61 + make_directories(local_file);
60 62 if file(local_file, new) is
61 63 {
62   - failure then println("Can't create \""+local_file+"\" file"),
  64 + failure then println("Can't create \""+local_file+"\" file"); failure,
63 65 success(fd) then //the local file is open
64 66 with start = message(_CXM_FTP_START_TRANSFERT),
65 67 mQ.add_Message_to_send(start);
... ... @@ -67,7 +69,7 @@ define One
67 69 }
68 70 .
69 71  
70   -define One
  72 +define Maybe(One)
71 73 get_file
72 74 (
73 75 MessageQueue mQ,
... ... @@ -77,27 +79,26 @@ define One
77 79 with get_file_msg = message(_CXM_FTP_GET_FILE),
78 80 if add_string(get_file_msg, "FileName", remote_file) is
79 81 {
80   - failure then unique,
  82 + failure then failure,
81 83 success(_) then
82 84 mQ.add_Message_to_send(get_file_msg);
83 85 println("_CXM_FTP_GET_FILE sent");
84 86 if wait_for_reply(mQ, _CXM_FTP_GET_FILE, 30) is
85 87 {
86   - failure then unique,
87   - timeout then unique,
88   - unknow_cmd then unique,
89   - error then unique,
90   - ok then unique,
  88 + failure then failure,
  89 + timeout then failure,
  90 + unknow_cmd then failure,
  91 + error then failure,
  92 + ok then failure,
91 93 ok_msg(msg)then
92 94 if find_int32(msg, "FileSize") is
93 95 {
94   - failure then println("file size not found"); unique,
  96 + failure then println("file size not found"); failure,
95 97 success(size) then
96 98 start_get_file_transtert(mQ, local_file, size)
97 99 }
98 100 }
99   - }
100   - .
  101 + }.
101 102  
102 103  
103 104 define Bool
... ... @@ -125,7 +126,7 @@ define Bool
125 126 }
126 127 }.
127 128  
128   -public define One
  129 +public define Maybe(One)
129 130 ftp_get_file
130 131 (
131 132 String server,
... ... @@ -136,16 +137,16 @@ public define One
136 137 if dns(server) is ok(ip_adr) then
137 138 if connect( ip_adr, ip_port) is
138 139 {
139   - error(_) then println("can't connect to ftp server"),
  140 + error(_) then println("can't connect to ftp server"); failure,
140 141 ok(conn) then
141 142 with queue = create_MessageQueue,
142 143 message_transceiver(conn, queue);
143 144 if request_for_service(queue) then
144 145 get_file(queue, remote_file, local_file)
145 146 else
146   - println("Service not found")
  147 + println("Service not found");failure
147 148 }
148 149 else
149   - println("server "+server+" DNS error")
  150 + println("server "+server+" DNS error");failure
150 151 .
151 152  
... ...