netwerk/sctp/src/ScopedFd.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

     1 /*
     2  * Copyright (C) 2009 The Android Open Source Project
     3  *
     4  * Licensed under the Apache License, Version 2.0 (the "License");
     5  * you may not use this file except in compliance with the License.
     6  * You may obtain a copy of the License at
     7  *
     8  *      http://www.apache.org/licenses/LICENSE-2.0
     9  *
    10  * Unless required by applicable law or agreed to in writing, software
    11  * distributed under the License is distributed on an "AS IS" BASIS,
    12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  * See the License for the specific language governing permissions and
    14  * limitations under the License.
    15  */
    17 #ifndef SCOPED_FD_H_included
    18 #define SCOPED_FD_H_included
    20 #include <unistd.h>
    22 // A smart pointer that closes the given fd on going out of scope.
    23 // Use this when the fd is incidental to the purpose of your function,
    24 // but needs to be cleaned up on exit.
    25 class ScopedFd {
    26 public:
    27     explicit ScopedFd(int fd) : fd(fd) {
    28     }
    30     ~ScopedFd() {
    31         close(fd);
    32     }
    34     int get() const {
    35         return fd;
    36     }
    38 private:
    39     int fd;
    41     // Disallow copy and assignment.
    42     ScopedFd(const ScopedFd&);
    43     void operator=(const ScopedFd&);
    44 };
    46 #endif  // SCOPED_FD_H_included

mercurial