本文整理汇总了C++中nsAutoPtr::CreateAddr方法的典型用法代码示例。如果您正苦于以下问题:C++ nsAutoPtr::CreateAddr方法的具体用法?C++ nsAutoPtr::CreateAddr怎么用?C++ nsAutoPtr::CreateAddr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nsAutoPtr
的用法示例。
在下文中一共展示了nsAutoPtr::CreateAddr方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: OnSocketEventTask
void
UnixSocketImpl::Connect()
{
MOZ_ASSERT(!NS_IsMainThread());
if (!mConnector) {
NS_WARNING("No connector object available!");
return;
}
if (mFd.get() < 0) {
mFd = mConnector->Create();
if (mFd.get() < 0) {
return;
}
}
int ret;
if (!mConnector->CreateAddr(false, mAddrSize, mAddr, mAddress.get())) {
NS_WARNING("Cannot create socket address!");
return;
}
ret = connect(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize);
if (ret) {
#if DEBUG
LOG("Socket connect errno=%d\n", errno);
#endif
mFd.reset(-1);
nsRefPtr<OnSocketEventTask> t =
new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
NS_DispatchToMainThread(t);
return;
}
if (!SetSocketFlags()) {
return;
}
if (!mConnector->SetUp(mFd)) {
NS_WARNING("Could not set up socket!");
return;
}
nsRefPtr<OnSocketEventTask> t =
new OnSocketEventTask(this, OnSocketEventTask::CONNECT_SUCCESS);
NS_DispatchToMainThread(t);
SetUpIO();
}
示例2: OnSocketEventTask
void
UnixSocketImpl::Connect()
{
if(mFd.get() < 0)
{
mFd = mConnector->Create();
if (mFd.get() < 0) {
return;
}
}
int ret;
socklen_t addr_sz;
struct sockaddr addr;
mConnector->CreateAddr(false, addr_sz, &addr, mAddress.get());
ret = connect(mFd.get(), &addr, addr_sz);
if (ret) {
#if DEBUG
LOG("Socket connect errno=%d\n", errno);
#endif
mFd.reset(-1);
nsRefPtr<OnSocketEventTask> t =
new OnSocketEventTask(this, OnSocketEventTask::CONNECT_ERROR);
NS_DispatchToMainThread(t);
return;
}
if (!mConnector->SetUp(mFd)) {
NS_WARNING("Could not set up socket!");
return;
}
nsRefPtr<OnSocketEventTask> t =
new OnSocketEventTask(this, OnSocketEventTask::CONNECT_SUCCESS);
NS_DispatchToMainThread(t);
// Due to the fact that we've dispatched our OnConnectSuccess message before
// starting reading, we're guaranteed that any subsequent read tasks will
// happen after the object has been notified of a successful connect.
XRE_GetIOMessageLoop()->PostTask(FROM_HERE,
new StartImplReadingTask(this));
}
示例3: LOG
void
UnixSocketImpl::Accept()
{
MOZ_ASSERT(!NS_IsMainThread());
if (!mConnector) {
NS_WARNING("No connector object available!");
return;
}
// This will set things we don't particularly care about, but it will hand
// back the correct structure size which is what we do care about.
if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) {
NS_WARNING("Cannot create socket address!");
return;
}
if (mFd.get() < 0) {
mFd = mConnector->Create();
if (mFd.get() < 0) {
return;
}
if (!SetSocketFlags()) {
return;
}
if (bind(mFd.get(), (struct sockaddr*)&mAddr, mAddrSize)) {
#ifdef DEBUG
LOG("...bind(%d) gave errno %d", mFd.get(), errno);
#endif
return;
}
if (listen(mFd.get(), 1)) {
#ifdef DEBUG
LOG("...listen(%d) gave errno %d", mFd.get(), errno);
#endif
return;
}
}
SetUpIO();
}
示例4: GetIOLoop
void
ListenSocketIO::Listen(ConnectionOrientedSocketIO* aCOSocketIO)
{
MOZ_ASSERT(MessageLoopForIO::current() == GetIOLoop());
MOZ_ASSERT(mConnector);
MOZ_ASSERT(aCOSocketIO);
if (!IsOpen()) {
int fd = mConnector->Create();
if (fd < 0) {
NS_WARNING("Cannot create socket fd!");
FireSocketError();
return;
}
if (!SetSocketFlags(fd)) {
NS_WARNING("Cannot set socket flags!");
FireSocketError();
return;
}
if (!mConnector->SetUpListenSocket(GetFd())) {
NS_WARNING("Could not set up listen socket!");
FireSocketError();
return;
}
// This will set things we don't particularly care about, but
// it will hand back the correct structure size which is what
// we do care about.
if (!mConnector->CreateAddr(true, mAddrSize, mAddr, nullptr)) {
NS_WARNING("Cannot create socket address!");
FireSocketError();
return;
}
SetFd(fd);
}
mCOSocketIO = aCOSocketIO;
// calls OnListening on success, or OnError otherwise
nsresult rv = UnixSocketWatcher::Listen(
reinterpret_cast<struct sockaddr*>(&mAddr), mAddrSize);
NS_WARN_IF(NS_FAILED(rv));
}