2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Paweł Dziepak, pdziepak@quarnos.org
12 #include "FileSystem.h"
17 Request::Send(Cookie
* cookie
)
19 switch (fServer
->ID().fProtocol
) {
20 case IPPROTO_UDP
: return _SendUDP(cookie
);
21 case IPPROTO_TCP
: return _SendTCP(cookie
);
29 Request::_SendUDP(Cookie
* cookie
)
31 RPC::Reply
* rpl
= NULL
;
34 status_t result
= fServer
->SendCallAsync(fBuilder
.Request(), &rpl
, &rpc
);
39 cookie
->RegisterRequest(rpc
);
41 int requestTimeout
= sSecToBigTime(60);
45 if (fFileSystem
!= NULL
) {
46 requestTimeout
= fFileSystem
->GetConfiguration().fRequestTimeout
;
47 retryLimit
= fFileSystem
->GetConfiguration().fRetryLimit
;
48 hard
= fFileSystem
->GetConfiguration().fHard
;
51 result
= fServer
->WaitCall(rpc
, requestTimeout
);
54 while (result
!= B_OK
&& (hard
|| attempts
++ < retryLimit
)) {
55 result
= fServer
->ResendCallAsync(fBuilder
.Request(), rpc
);
58 cookie
->UnregisterRequest(rpc
);
63 result
= fServer
->WaitCall(rpc
, requestTimeout
);
68 cookie
->UnregisterRequest(rpc
);
69 fServer
->CancelCall(rpc
);
76 cookie
->UnregisterRequest(rpc
);
78 if (rpc
->fError
!= B_OK
) {
92 Request::_SendTCP(Cookie
* cookie
)
94 RPC::Reply
* rpl
= NULL
;
100 int requestTimeout
= sSecToBigTime(60);
104 if (fFileSystem
!= NULL
) {
105 requestTimeout
= fFileSystem
->GetConfiguration().fRequestTimeout
;
106 retryLimit
= fFileSystem
->GetConfiguration().fRetryLimit
;
107 hard
= fFileSystem
->GetConfiguration().fHard
;
111 result
= fServer
->SendCallAsync(fBuilder
.Request(), &rpl
, &rpc
);
112 if (result
== B_NO_MEMORY
)
114 else if (result
!= B_OK
) {
120 cookie
->RegisterRequest(rpc
);
122 result
= fServer
->WaitCall(rpc
, requestTimeout
);
123 if (result
!= B_OK
) {
125 cookie
->UnregisterRequest(rpc
);
127 fServer
->CancelCall(rpc
);
132 } while (result
!= B_OK
&& (hard
|| attempts
++ < retryLimit
));
138 cookie
->UnregisterRequest(rpc
);
140 if (rpc
->fError
!= B_OK
) {
142 result
= rpc
->fError
;