Files
sdk/runtime/bin/fdutils.h
T
kustermann@google.com 6d1cda397c Added FD_CLOEXEC flag to client/server socket file descriptors
Without the FD_CLOEXEC, all subprocesses will inherit the open socket
file descriptors of the current process due to the default behavior
of fork()+exec().

Review URL: https://codereview.chromium.org//11416006

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@14952 260f80e4-7a28-3924-810f-c04153c831b5
2012-11-15 11:27:33 +00:00

45 lines
1.6 KiB
C++

// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
#ifndef BIN_FDUTILS_H_
#define BIN_FDUTILS_H_
#include "bin/builtin.h"
#include "platform/globals.h"
class FDUtils {
public:
static bool SetCloseOnExec(intptr_t fd);
static bool SetNonBlocking(intptr_t fd);
static bool SetBlocking(intptr_t fd);
// Checks whether the file descriptor is blocking. If the function
// returns true the value pointed to by is_blocking will be set to
// the blocking state of the file descriptor. If the function
// returns false the system call for checking the file descriptor
// failed and the value pointed to by is_blocking is not modified.
static bool IsBlocking(intptr_t fd, bool* is_blocking);
static intptr_t AvailableBytes(intptr_t fd);
// Reads the requested number of bytes from a file descriptor. This
// function will only return on short reads if an error occours in
// which case it returns -1 and errno is still valid. The file
// descriptor must be in blocking mode.
static ssize_t ReadFromBlocking(int fd, void* buffer, size_t count);
// Writes the requested number of bytes to a file descriptor. This
// function will only return on short writes if an error occours in
// which case it returns -1 and errno is still valid. The file
// descriptor must be in blocking mode.
static ssize_t WriteToBlocking(int fd, const void* buffer, size_t count);
private:
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(FDUtils);
};
#endif // BIN_FDUTILS_H_