BPicture: Fix archive constructor.
[haiku.git] / src / add-ons / kernel / file_systems / nfs4 / Request.cpp
blob96fa49ca34dcb31cbd18e584fe1353215f58f372
1 /*
2 * Copyright 2012 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Paweł Dziepak, pdziepak@quarnos.org
7 */
10 #include "Request.h"
12 #include "FileSystem.h"
13 #include "Inode.h"
16 status_t
17 Request::Send(Cookie* cookie)
19 switch (fServer->ID().fProtocol) {
20 case IPPROTO_UDP: return _SendUDP(cookie);
21 case IPPROTO_TCP: return _SendTCP(cookie);
24 return B_BAD_VALUE;
28 status_t
29 Request::_SendUDP(Cookie* cookie)
31 RPC::Reply* rpl = NULL;
32 RPC::Request* rpc;
34 status_t result = fServer->SendCallAsync(fBuilder.Request(), &rpl, &rpc);
35 if (result != B_OK)
36 return result;
38 if (cookie != NULL)
39 cookie->RegisterRequest(rpc);
41 int requestTimeout = sSecToBigTime(60);
42 int retryLimit = 0;
43 bool hard = true;
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);
52 if (result != B_OK) {
53 int attempts = 1;
54 while (result != B_OK && (hard || attempts++ < retryLimit)) {
55 result = fServer->ResendCallAsync(fBuilder.Request(), rpc);
56 if (result != B_OK) {
57 if (cookie != NULL)
58 cookie->UnregisterRequest(rpc);
59 delete rpc;
60 return result;
63 result = fServer->WaitCall(rpc, requestTimeout);
66 if (result != B_OK) {
67 if (cookie != NULL)
68 cookie->UnregisterRequest(rpc);
69 fServer->CancelCall(rpc);
70 delete rpc;
71 return result;
75 if (cookie != NULL)
76 cookie->UnregisterRequest(rpc);
78 if (rpc->fError != B_OK) {
79 delete rpl;
80 result = rpc->fError;
81 delete rpc;
82 return result;
83 } else {
84 fReply.SetTo(rpl);
85 delete rpc;
86 return B_OK;
91 status_t
92 Request::_SendTCP(Cookie* cookie)
94 RPC::Reply* rpl = NULL;
95 RPC::Request* rpc;
97 status_t result;
98 int attempts = 0;
100 int requestTimeout = sSecToBigTime(60);
101 int retryLimit = 0;
102 bool hard = true;
104 if (fFileSystem != NULL) {
105 requestTimeout = fFileSystem->GetConfiguration().fRequestTimeout;
106 retryLimit = fFileSystem->GetConfiguration().fRetryLimit;
107 hard = fFileSystem->GetConfiguration().fHard;
110 do {
111 result = fServer->SendCallAsync(fBuilder.Request(), &rpl, &rpc);
112 if (result == B_NO_MEMORY)
113 return result;
114 else if (result != B_OK) {
115 fServer->Repair();
116 continue;
119 if (cookie != NULL)
120 cookie->RegisterRequest(rpc);
122 result = fServer->WaitCall(rpc, requestTimeout);
123 if (result != B_OK) {
124 if (cookie != NULL)
125 cookie->UnregisterRequest(rpc);
127 fServer->CancelCall(rpc);
128 delete rpc;
130 fServer->Repair();
132 } while (result != B_OK && (hard || attempts++ < retryLimit));
134 if (result != B_OK)
135 return result;
137 if (cookie != NULL)
138 cookie->UnregisterRequest(rpc);
140 if (rpc->fError != B_OK) {
141 delete rpl;
142 result = rpc->fError;
143 delete rpc;
144 return result;
147 fReply.SetTo(rpl);
148 delete rpc;
149 return B_OK;
153 void
154 Request::Reset()
156 fBuilder.Reset();
157 fReply.Reset();