Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
86e2075c
Commit
86e2075c
authored
Jul 06, 2018
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lib/nfs/Connection: use new class NfsClientError
Allows callers to extract the NFS error code.
parent
30900b2f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
146 additions
and
1 deletion
+146
-1
Makefile.am
Makefile.am
+1
-0
Error.cxx
src/input/Error.cxx
+9
-0
Connection.cxx
src/lib/nfs/Connection.cxx
+2
-1
Error.cxx
src/lib/nfs/Error.cxx
+76
-0
Error.hxx
src/lib/nfs/Error.hxx
+58
-0
No files found.
Makefile.am
View file @
86e2075c
...
...
@@ -713,6 +713,7 @@ NFS_SOURCES = \
src/lib/nfs/Cancellable.hxx
\
src/lib/nfs/Lease.hxx
\
src/lib/nfs/Connection.cxx src/lib/nfs/Connection.hxx
\
src/lib/nfs/Error.cxx src/lib/nfs/Error.hxx
\
src/lib/nfs/Manager.cxx src/lib/nfs/Manager.hxx
\
src/lib/nfs/Glue.cxx src/lib/nfs/Glue.hxx
\
src/lib/nfs/Base.cxx src/lib/nfs/Base.hxx
\
...
...
src/input/Error.cxx
View file @
86e2075c
...
...
@@ -21,6 +21,11 @@
#include "Error.hxx"
#include "system/Error.hxx"
#ifdef ENABLE_NFS
#include "lib/nfs/Error.hxx"
#include <nfsc/libnfs-raw-nfs.h>
#endif
bool
IsFileNotFound
(
std
::
exception_ptr
ep
)
{
...
...
@@ -28,6 +33,10 @@ IsFileNotFound(std::exception_ptr ep)
std
::
rethrow_exception
(
ep
);
}
catch
(
const
std
::
system_error
&
e
)
{
return
IsFileNotFound
(
e
);
#ifdef ENABLE_NFS
}
catch
(
const
NfsClientError
&
e
)
{
return
e
.
GetCode
()
==
NFS3ERR_NOENT
;
#endif
}
catch
(...)
{
}
...
...
src/lib/nfs/Connection.cxx
View file @
86e2075c
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "Connection.hxx"
#include "Error.hxx"
#include "Lease.hxx"
#include "Callback.hxx"
#include "event/Loop.hxx"
...
...
@@ -139,7 +140,7 @@ NfsConnection::CancellableCallback::Callback(int err, void *data)
if
(
err
>=
0
)
cb
.
OnNfsCallback
((
unsigned
)
err
,
data
);
else
cb
.
OnNfsError
(
std
::
make_exception_ptr
(
std
::
runtime_error
(
(
const
char
*
)
data
)));
cb
.
OnNfsError
(
std
::
make_exception_ptr
(
NfsClientError
(
-
err
,
(
const
char
*
)
data
)));
}
else
{
if
(
open
)
{
/* a nfs_open_async() call was cancelled - to
...
...
src/lib/nfs/Error.cxx
0 → 100644
View file @
86e2075c
/*
* Copyright 2007-2017 Content Management AG
* All rights reserved.
*
* author: Max Kellermann <mk@cm4all.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Error.hxx"
#include "util/StringFormat.hxx"
extern
"C"
{
#include <nfsc/libnfs.h>
}
#include <assert.h>
#include <string.h>
static
StringBuffer
<
256
>
FormatNfsClientError
(
struct
nfs_context
*
nfs
,
const
char
*
msg
)
noexcept
{
assert
(
msg
!=
nullptr
);
const
char
*
msg2
=
nfs_get_error
(
nfs
);
return
StringFormat
<
256
>
(
"%s: %s"
,
msg
,
msg2
);
}
NfsClientError
::
NfsClientError
(
struct
nfs_context
*
nfs
,
const
char
*
msg
)
noexcept
:
std
::
runtime_error
(
FormatNfsClientError
(
nfs
,
msg
).
c_str
()),
code
(
0
)
{}
static
StringBuffer
<
256
>
FormatNfsClientError
(
int
err
,
struct
nfs_context
*
nfs
,
void
*
data
,
const
char
*
msg
)
noexcept
{
assert
(
msg
!=
nullptr
);
assert
(
err
<
0
);
const
char
*
msg2
=
(
const
char
*
)
data
;
if
(
data
==
nullptr
||
*
(
const
char
*
)
data
==
0
)
{
msg2
=
nfs_get_error
(
nfs
);
if
(
msg2
==
nullptr
)
msg2
=
strerror
(
-
err
);
}
return
StringFormat
<
256
>
(
"%s: %s"
,
msg
,
msg2
);
}
NfsClientError
::
NfsClientError
(
int
err
,
struct
nfs_context
*
nfs
,
void
*
data
,
const
char
*
msg
)
noexcept
:
std
::
runtime_error
(
FormatNfsClientError
(
err
,
nfs
,
data
,
msg
).
c_str
()),
code
(
-
err
)
{}
src/lib/nfs/Error.hxx
0 → 100644
View file @
86e2075c
/*
* Copyright 2007-2017 Content Management AG
* All rights reserved.
*
* author: Max Kellermann <mk@cm4all.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef NFS_ERROR_HXX
#define NFS_ERROR_HXX
#include <stdexcept>
class
NfsClientError
:
public
std
::
runtime_error
{
int
code
;
public
:
explicit
NfsClientError
(
const
char
*
_msg
)
noexcept
:
std
::
runtime_error
(
_msg
),
code
(
0
)
{}
NfsClientError
(
int
_code
,
const
char
*
_msg
)
noexcept
:
std
::
runtime_error
(
_msg
),
code
(
_code
)
{}
NfsClientError
(
struct
nfs_context
*
nfs
,
const
char
*
msg
)
noexcept
;
NfsClientError
(
int
err
,
struct
nfs_context
*
nfs
,
void
*
data
,
const
char
*
msg
)
noexcept
;
int
GetCode
()
const
noexcept
{
return
code
;
}
};
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment