Setting custom baud rates on debian for BBB

I am trying to set a baud rate of 250K for my UARTS. I have the following (using debian):

[code]
`
int speed=250000;

struct serial_struct ser_info;

struct termios options;

ser_info.reserved_char[0] = 0;

ioctl(handle, TIOCGSERIAL, &ser_info);

ser_info.flags = (ser_info.flags & ~ASYNC_SPD_MASK) | ASYNC_SPD_CUST;

ser_info.custom_divisor = (ser_info.baud_base + (speed/2) ) / speed;

int closestSpeed = ser_info.baud_base / ser_info.custom_divisor;

if (closestSpeed < speed * 98 / 100 || closestSpeed > speed * 102 / 100)

{

std::cout <<" Cannot set serial port speed to “<<speed<<” closest possible is " <<closestSpeed<<std::endl;

}

else

std::cout <<"Setting speed to " << closestSpeed<<std::endl;

if (ioctl(handle, TIOCSSERIAL, &ser_info)<0)

{

std::cout <<"Error setting serial options: "<< strerror(errno) <<std::endl;

}

`

However, this always returns an error on the last ioctl to set the custom divisor (it says invalid parameter). Any helpful insight?