Catch 'address already in use' error when trying to use a port that is

in use by another program.  We now try to use a range of 40000-60000 
when this error occurs.
This commit is contained in:
Andrew Resch 2008-01-14 08:04:28 +00:00
parent 642663604f
commit cc81e1073d
1 changed files with 8 additions and 2 deletions

View File

@ -640,8 +640,14 @@ static PyObject *torrent_set_listen_on(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "O", &port_vec))
return NULL;
M_ses->listen_on(std::make_pair( PyInt_AsLong(PyList_GetItem(port_vec, 0)),
PyInt_AsLong(PyList_GetItem(port_vec, 1))), "");
try {
M_ses->listen_on(std::make_pair( PyInt_AsLong(PyList_GetItem(port_vec, 0)),
PyInt_AsLong(PyList_GetItem(port_vec, 1))), "");
}
catch (...) {
//Can't listen on that port, so lets try a range of 40000-60000
M_ses->listen_on(std::make_pair(40000, 60000), "");
}
Py_INCREF(Py_None); return Py_None;
}