Commit 44e48457 authored by Andre Pinto's avatar Andre Pinto Committed by Dave Watson

Correct getsockopt call made by AsyncSocket

Summary:
The getsockopt's last parameter (optlen) is a value-result parameter
and AsyncSocket::getSockOpt was passing a value as argument.

Test Plan: Unit tests

Reviewed By: alikhtarov@fb.com

Subscribers: trunkagent, njormrod, folly-diffs@

FB internal diff: D1717463

Tasks: 4867290

Signature: t1:1717463:1417664828:6c7a74ff31725121f892ce1adba2653e70728192
parent 35ed5364
...@@ -530,11 +530,14 @@ class AsyncSocket : virtual public AsyncTransport { ...@@ -530,11 +530,14 @@ class AsyncSocket : virtual public AsyncTransport {
* @param optname same as the "optname" parameter in getsockopt(). * @param optname same as the "optname" parameter in getsockopt().
* @param optval pointer to the variable in which the option value should * @param optval pointer to the variable in which the option value should
* be returned. * be returned.
* @param optlen value-result argument, initially containing the size of
* the buffer pointed to by optval, and modified on return
* to indicate the actual size of the value returned.
* @return same as the return value of getsockopt(). * @return same as the return value of getsockopt().
*/ */
template <typename T> template <typename T>
int getSockOpt(int level, int optname, T *optval) { int getSockOpt(int level, int optname, T* optval, socklen_t* optlen) {
return getsockopt(fd_, level, optname, optval, sizeof(T)); return getsockopt(fd_, level, optname, (void*) optval, optlen);
} }
/** /**
......
/*
* Copyright 2014 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <iostream>
#include <folly/io/async/AsyncSocket.h>
#include <folly/io/async/EventBase.h>
#include <gtest/gtest.h>
TEST(AsyncSocketTest, getSockOpt) {
folly::EventBase evb;
std::shared_ptr<folly::AsyncSocket> socket =
folly::AsyncSocket::newSocket(&evb, 0);
int val;
socklen_t len;
int expectedRc = getsockopt(socket->getFd(), SOL_SOCKET,
SO_REUSEADDR, &val, &len);
int actualRc = socket->getSockOpt(SOL_SOCKET, SO_REUSEADDR, &val, &len);
EXPECT_EQ(expectedRc, actualRc);
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment